(Trying to) Sanely Deal with Maven Dependency Versions
Posted by Tejus Parikh on November 5, 2011
One challenge of the maven way is how to sensibly version dependencies in a large, but constantly changing, project.
In the ideal maven world, each module is a highly defined project, with a highly structured team and releases only occur once the contract has been fully defined, tested, and whatever else enterprise teams do. In many realities, projects are simply logical constructs that don't have strict contracts between the other module. The production environment is a mix of highly stable and rigorously tested products and experimental, pushed-constantly projects.
In this environment, automatic versioning of dependencies is both unnecessary and costly, and the dependencies need to be frozen at branch time of the stable, top-level projects. The other requirement is that the changes to the poms need to be minimal, so that any merge conflicts can be easily resolved.
The approach I've used, combining a few different ideas from the internet, is to remove any version numbers referencing internal projects from child modules. The versions are then included as properties in the parent project.
Freezing the set of dependencies for the module tree is then a three part process of:
- Change the version number in the parent pom
- Change the version properties of the parent pom
- Change the parent version number in the child poms
To illustrate how this works, consider a project that has com.tejusparikh.web with a parent pom com.tejusparikh.
If you wanted to freeze the poms at 1.0.RELEASE then the poms would look like the following:
The point is that every child pom would have a property as it's version number, making it easy to manage an arbitrary number of children.
Of course, you don't want to have to update everything manually. The only method I've found to effectively use maven is to wrap it all in rake. Therefore, I've created a rake task to recurse the directories and change the version numbers.
Freezing all of your poms is as simple as calling rake mvn:version[/path/to/parent/dir,VERSION].