mavenbuildpom.xmlmaven-archetypegiter8

Modern Maven Pom Templates


Every time I make a new proper project using Maven hosted on Github I have to go look at either one of my own old projects and copy the pom file or I go find a project that I think does a good job and copy there POM file. Then I have to go search and replace things like project name... etc.

Now Maven has a solution to this through archetypes but I have yet to see one that is modern enough such that it:

I have contemplated make some giter8 templates but was hoping somebody already did something like this (most of the g8 templates are for sbt).


Solution

  • It turns out its incredible easy to create your own maven archetype.

    1. Just make a generic project with stuff you like to use
    2. In the project directory run mvn archetype:create-from-project
    3. Generally Maven guesses the right things to make variable but if not you just edit the Velocity templates.
    4. Install your archetype locally with mvn install
    5. To use your new archetype: mvn archetype:generate -DarchetypeGroupId=com.mygroup -DarchetypeArtifactId=my-archetype

    Now the only caveat is that there is not very good doc on the web that I could find on the archetype system. Like its unclear what variables you have available to you for Velocity (although most of them are obvious).

    http://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html