Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven versioning best practices [closed]

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.

like image 674
shabunc Avatar asked Mar 04 '12 12:03

shabunc


People also ask

Why is it best practice not to release snapshots of Maven artifacts?

Rule #3 Never release using the Time-Stamped snapshot The release plugin will still fail if you do this because it correctly understands you have SNAPSHOT dependencies. The plugin has a flag to allow bypass this check and people unfortunately use it far too often.

What is M1 in Maven version?

M1 means Milestone 1, it's a release name, like beta or alpha. RC means Release Candidate.

Is version mandatory in POM XML?

Each maven dependency defined in the pom must have a version either directly or indirectly for example, through dependencyManagement or parent. That being said, if the version is not given, then the version provided in the dependencyManagement or the parent pom will be used.

What will happen if the Maven version number of POM XML file does not match with the machine used to install?

Maven won't allow any other either. Build will fail if version is not found.


1 Answers

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?).

like image 187
khmarbaise Avatar answered Nov 23 '22 11:11

khmarbaise