Home > Maven, Solutions Log > Maven Multi Module Versioning

Maven Multi Module Versioning

Recently I have been working on a Maven multi module project with ear, war and ejb artifacts. It has been a pleasant experience till I got to versioning my modules. Consider a multi module project with the following structure:

parent-project
|
|- child-moudle
| |
| |–pom.xml
|
|- pom.xml

The parent project pom.xml holds the version information of the parent project:

com.inflinx
project-parent
1.0.0-SNAPSHOT
pom

Now the child module pom contains a reference to the parent information:


	com.inflinx
	project-parent
	1.0.0-SNAPSHOT


4.0.0
com.inflinx
child-module
jar

Now this is where the problem starts. Since all the child modules need to have an explicit reference to the parent pom version, when it is time to do a release, we have to change the version in parent pom and all the child module poms. This can be a real pain and is very error prone. With a little help from Google, here is what I found:

  1. Ceki on his blog suggested using a property in the parent pom to control the version numbering.
  2. Several maven users would like “automatic parent versioning” according this improvement
  3. Use maven release plugin which would automate the process of changing version numbers across the project

Option three seems to be the correct approach to solve this problem here. But I have heard horrible things about the release plugin and how fragile it is. I will be giving it a try soon. I still think that Maven should support automatic parent versioning as an option for users who don’t (or cannot) get to use the release plugin.

Categories: Maven, Solutions Log Tags: ,
  1. May 21st, 2010 at 08:13 | #1

    I’ve been using the release plugin for years without problems. Both for multi-module and single module releases, it’s great. It takes a bit of playing to get all your ducks in a row, what with all the different possible ways of doing multi-module projects.

    I wouldn’t go back to doing it manually. And I like that all my jars are built off svn tags made by the plugin, it gives a nice level of determinism.

  2. wog
    May 25th, 2010 at 01:44 | #2

    Just use the versions plugin and it will change all your poms:
    mvn versions:set -DnewVersion=1.2.3-your-new-version

  3. May 25th, 2010 at 08:31 | #3

    @wog
    Thanks wog. I will give versions plugin a try

  4. Bruno Medeiros
    May 29th, 2010 at 09:47 | #4

    I’ve been using the release plugin for years without problems too.

    Some tips to avoid problems:
    1. Double check svn urls in poms
    2. Use hte console directly to do releases, maven release plugins will need svn working on console mode, so use some ide integration to release will only bring more problems.
    3. ALWAYS do a ‘svn update’ before the release.

  5. Caoilte
    September 7th, 2010 at 12:14 | #5

    Thanks for this post. I’m just starting out with a multi-module project and this is a very obvious deficiency that isn’t covered in the official docs.

  6. Sachin
    April 4th, 2011 at 12:02 | #6

    @David Roussel
    Hi David
    Can you help me set up my multi module project for the maven release. i am going to start using the maven release. We have been using multi module project without any problem we just need to set up the relase.

    Lets say i have Parent which has 2 modules in it – one builds jar and 1 builds war and they both are in parent which builds these 2 sub modules. war is the last module. First it builds jar and then war which is dependent on jar. Is it possible to do a release for such kind of project?

    Please let me know, you can email me at sachin_batra@hotmail.com

  1. No trackbacks yet.