Wednesday, July 19, 2006

Build Numbers in jars build with Maven

Build Numbers for Maven builds using Cruise Control.

Maven is a very useful tool. For the most part, you can get it to do whatever you want, but the trick is finding out how. One issue that my team had was:
  • We're using Cruise Control
  • We'd like to have the CC build number in the Jar Manifests
  • We're using Maven to build.
There are a couple of ways that you could do this, using ant from within maven, but that seems like extra work or at least extra complexity. The solution we found was:

Configure the project POM file to add a manifest to the jar. Most of the following is just using the maven Plugin. There is a great guide to manifests on the maven site so I'll only show the parts relevant to configuring the manifest to add a cruise control build number.
<addExtensions />
This will set a buildNumber field in the manifest to the value of the build.number property. The trick is to get the property into maven. To do this you take advantage of the properties that cruise control makes available to you. I am using the cruise control AntBuilder to launch maven. So my cruise control config.xml looks like:
<ant antscript="/usr/local/ant/bin/ant"
uselogger="true" usedebug="true" target="">
<property name="maven.path" value="/usr/local/maven2/bin/mvn"/>
Implicitly, CruiseControl makes some properties available to you:
<target name="" depends="cvsUpdate">
<mkdir dir="target" />
<exec executable="${maven.path}" dir="${basedir}" failonerror="true" output="build.out" logError="true">
<arg line="-Dbuild.number=${label} clean package assembly:assembly install" />
by adding the line -Dbuild.number=${label} you can pass the CC label for the build on to maven.

No comments:

Site Reliability Engineering; The Book and The Practices

Site Reliability Engineering It’s difficult to walk into a software development organization without hearing about the discipline of Site ...