Maven automatic build versioning and Git against Subversion

One of the nicest features of Git is that it’s possible to use it locally against a Subversion server. For many this is a crucial selling point as it allows individual developers to take advantage of Git while not requiring that the entire project switches version control from Subversion. On your local Git repository you’re then free to do as many branches as you like, or otherwise take advantage of the many nice features in Git.

However, if your project is set up to use the Maven automatic build versioning as provided by the buildnumber-maven-plugin you will run into problems if it is set to get the build numbers from the Subversion revision number. Since your local checkout is against Git, and not Subversion, the build will fail since the Subversion commands won’t work.
One solution for this could be to alter the plugin configuration to get the build number from the date or something similar, but that’s not always possible. You might have a build server setup that depends on the build number matching the revision number, and imposing such a change might break other functionality or processes.

Instead you can add an additional profile to the Maven POM which will only be triggered in the absence of a .svn directory (i.e. when not using Subversion). In this profile you can override the default configuration for the build number generator to instead use the date for build numbers. This means that your builds will have different build numbers from the integration builds, but at least it will compile on your git checkout.

The profile will look like this:

This way Subversion and Git users can live happily together in the same project.

This Post Has 7 Comments

  1. This is an excellent suggestion. I’ll share it with some students in my next Maven class on Git + SVN dual-use environments.

  2. Thank you, that is useful!

  3. I’m sure I got inspiration for it from somewhere, but I can’t remember exactly from where. It might very well be from EHCache, but the fact that you added it to the core pom in commit 2678 which is dated 2010-08-25, i.e. almost a year after this blog post was written, seems to contradict that assertion.

Leave a Reply

Close Menu