Maven versioning best practices

shabunc picture shabunc · Mar 4, 2012 · Viewed 71.4k times · Source

What is the best way to change version of Maven project, to release this version and then return back to *-SNAPSHOT development.

Currently I'm doing following:

  • retrieve current version (most likely with SNAPSHOT) from pom.xml
  • increment version (mvn -DnewVersion=<something> versions:set), respecting rules described in the question Maven artifact version for patches
  • mvn:install to sent to repo
  • renaming version once again adding SNAPSHOT postfix.
  • committing changes (using some version control system)

I have a strong feeling I'm doing something wrong and/or inefficient.

Answer

khmarbaise picture khmarbaise · Mar 4, 2012

You should use the maven-release-plugin to release your artifacts. Than automatically all your versions will be incremented by the release-plugin. The exception might be if you are going from 1.0.3-SNAPSHOT to 1.1.0-SNAPSHOT . The timeline for developing with Maven is:

1.0.0-SNAPSHOT
1.0.0
1.0.1-SNAPSHOT
1.0.1
1.0.2-SNAPSHOT
1.0.2
..

To go for the step from a SNAPSHOT to a release version you should use the maven release plugin you can release an artifact simply by using:

First step:

mvn release:prepare 

The final step:

mvn release:perform

If you would like to accept the defaults you can simply add -B like:

mvn -B release:prepare 

or you can combine those steps into a single one:

mvn -B release:prepare release:perform

The above can also be used from within a CI solution.

Using mvn install is only intended to install the artifacts into your local repository. If you are working with a real one like a repository manager (which i can recommend) you have to use:

mvn deploy 

One requirement for using the release plugin is to configure the scm area in your pom (i hope you are using a version control?).