Question

What are the best practices for software versioning and multimodules projects with Maven?

I mean, when I create a multimodules project with Maven, what is the best approach for the versioning? To use a single version for all the modules (defined in the top project)? To use a version for each module (defined in the POM of each module)? Is there another approach that I'm missing? What are the pros and cons of each approach?

In general, are the different modules released together (possibly sharing the same version number)?

Thanks

Was it helpful?

Solution

Honestly it depends on what you would like to do. Multimodule projects are created for multiple reasons, one of them being you only need to deploy what has changed instead of all modules.

Think about it this way: if you had a non-multi-module project and you only had to change one line in the services layer, you have to rebuild the entire project and deploy all of the code again...even though only your services layer will change.

With multi-module projects, you can regenerate your project and deploy only what changed...your services. This reduces risk and you're assured that only your services module changed.

You also have a multitude of benefits to using multi-module projects that I'm not listing here but there is certainly a huge benefit to NOT keeping your version numbers of your modules in sync.

When you build your project, consider deploying it to a repository that will hold all compatible jars together for builds (each build creates a new folder with the parent-most pom version number). That way, you don't need to keep documentation about which jars are compatible...they're all just deployed together with a build number.

OTHER TIPS

I was looking for a solution for this exact problem myself and versions-maven-plugin was exactly what I needed. I don't like the release plugin communicating with the SCM system. The versions plugin does just what we need: it sets a new version number in all poms of the project:

mvn versions:set -DnewVersion=2.0.0

Then I can proceed with commits, tags and an official build server build...

EDIT:

The versions plugin depends on how a maven multi-module project has been organised: as a result, it often does not update all POM files in a complex multi-module project. I've found that sed and find do the job much more reliably:

sed -i 's/1.0.0-SNAPSHOT/1.0.0-RC1/g' `find . -name 'pom.xml'`

Typically you create a multi-module project because you have deemed that the various modules are parts of a single whole. Maybe the client-piece, the controller-piece and the services-piece. Or maybe the UI with services.

In any case, it makes sense to have the version numbers for the various modules to move in lock-step. However Maven does not enforce that as a rule.

As to your question

are the different modules released together (possibly sharing the same version number)

I would think so. That is one of the reasons for having it a multi-module project. Otherwise you could have the modules as independent projects.

Of course this is the kind of stuff that is rife with edge cases and exceptions ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top