Modern Maven Pom Templates

2.2k views Asked by At

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:

  • Uses the release plugin and deploys to SonaType Central Maven reop.
  • Connects to Github (meaning the scm connections and release plugin work do the right thing)
  • Makes all three jar artifacts (sources, javadoc, and regular jar)

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

3

There are 3 answers

0
Adam Gent On BEST ANSWER

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

2
Martin Ellis On

You could have a look at the parent pom released by Sonatype. It's intended to be used as a parent pom for projects that deploy to oss.sonatype.org (which may or may not be promoted to Maven Central).

When the sonatype-oss-release profile is enabled, it will ensure that sources and javadocs are built. It also includes an example of the <scm> pom element.

0
yegor256 On

You can use com.jcabi:parent:pom which does exactly what you need and many more. It deploys to Sonatype, defines common dependencies with versions, pre-configures most popular plugins, and defines a few useful profiles.

This article explains more: Don't Repeat Yourself in Maven POMs; Use Jcabi-Parent