Tejus's Programming and startup blog

  • Archive
  • RSS
  • Ask me anything

(Trying to) Sanely Deal with Maven Dependency Versions

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.

http://gist.github.com/1341577

http://gist.github.com/1341587

If you wanted to freeze the poms at 1.0.RELEASE then the poms would look like the following:

http://gist.github.com/1341596

http://gist.github.com/1341597

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.

http://gist.github.com/1341631

Freezing all of your poms is as simple as calling rake mvn:version[/path/to/parent/dir,VERSION].

  • 3 months ago
  • Comments
  • Permalink
  • Share
    Tweet

Recent comments

Blog comments powered by Disqus
← Previous • Next →

About

Avatar

I'm Tejus Parikh and this is my blog about programming, startups, and other technology related topics.

The vast majority of the posts are about Java or Ruby code, with a few about startups or gadgets thrown in for color.

You can learn more about me on Github and my personal homepage.

Me, Elsewhere

  • @vi_jedi on Twitter
  • Facebook Profile
  • Linkedin Profile
  • vijedi on github
  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr