Maven based configuration management with automatic build number 1491244277 69da7f912f o1

Maven based configuration management with automatic build number

An important questions in software deployment and testing is “What is the version of the software I am looking at”. It is frustrating for a tester or an end user not knowing if the planned upgrade is performed or not. Having a solid version numbering policy is a solution to overcome these problems.

There are several places where you want to have the version number of your software available:
– visible for the end user on the login screen.
– visible in the software distribution package (war / ear) for the deployment operator.
– visible in configuration files.
– and even visible in the deployed online manual.

The task of proper version numbering can be performed manually. This takes a solid knowledge of all places where this number is used and a good deal of perseverance when performing these repeating actions.
In a project under development, using an agile development method, there will be frequent builds and releases (daily or even hourly). This asks for automated build numbering. When using maven and subversion, this task can be automated with the maven buildnumber plugin.

Maven buildnumber plugin

June this year I found the maven buildnumber plugin on the internet. This plugin was first only hosted at the University of Calgary. Since this week the buildnumber plugin (http://mojo.codehaus.org/buildnumber-maven-plugin/index.html) is available in the Central maven repository http://repo1.maven.org/maven2/.

Configuring the Maven Buildnumber Plugin

When using the Maven Buildnumber Plugin you have to add the following lines to the master pom.xml. The phase configuration will make sure the builnumber is determined at the very start of the maven build cycle.

<build>
<……>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>true</doUpdate>
</configuration>
</plugin>
</plugins>
<…..>
</build>

See the Mojo sites for advanced configuration. http://mojo.codehaus.org/buildnumber-maven-plugin/create-mojo.html

Formatting

You can use the following options for build numbering configuration:
Default:

The default configuration (as above) will use the revision number form your SCM system.
This will produce in case of subversuion e.g. buildnumber: 1533

Timestamp:

<configuration>
<format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
<items>
<item>timestamp</item>
</items>
</configuration>

This will produce e.g buildnumber: 2007-11-06 2:32:35


Custom number, combined with text:

<configuration>
<format>Build {0,time} on {0,date} on {1} server.</format>
<items>
<item>timestamp</item>
<item>Autmatic build</item>
</items>
</configuration>

This will produce e.g buildnumber: Build 12:32 PM on Nov 6 on Autmatic build server.

Using the buildnumber plugin in your project.

Naming the produced artefacts with the buildnumber.

When you create the final name of the artefact (the EAR or WAR file) dynamically you can use the buildnumer to distinguish different versions of this artefact.

<build>
<finalName>${project.artifactId}-${project.version}-r${buildNumber}</finalName>
< €¦..>
</build>

This will result in an artefact in the target folder with the buildnumber in the name. E.g.
weblv-ap-1.0-SNAPSHOT-r14-11-2007-09.47.34.war

Resources file

The same buildnumber can be used in your resources file (e.g. an i18n resource file)`

Use the property

login.version=Versie: ${project.version}- build date ${buildNumber}

After processing resources (mvn process-resources) the login.version in the target folder will state:

login.version=Versie: 1.0-SNAPSHOT-  build date 14-11-2007 09.47.34

This property can be used on the login page (see image). This will show to all users when the current version is build.

Maven based configuration management with automatic build number buildnumber

Conclusion

This easy to use simple plugin is a step forward in Maven based software automation. This feature adds values to your project, especially for configuration managers, testers and key users. Not only during development but also in maintenance mode this plugin is very helpful.

9 Comments

  1. Stewart October 24, 2011
  2. Matteo Pelucco January 14, 2011
  3. Robbrecht van Amerongen August 24, 2009
  4. Lui Gie August 14, 2009
  5. Robbrecht van Amerongen August 13, 2009
  6. Peter Kahn August 5, 2009
  7. Zeger Hendrikse January 28, 2008
  8. Robbrecht van Amerongen December 2, 2007
  9. Zeger Hendrikse November 26, 2007