Tuesday, September 15, 2009

Build numbers & release dates with Maven


Having the build date & build number is a common requirement in any build system. Often, documents such as release notes & readme files need to contain this information. If your project uses Maven 2.x, here is how you do it.



1. Add the plugin repository

<pluginRepositories>
<pluginRepository>
<id>tlc</id>
<name>TLC Repository</name>
<url>http://commons.ucalgary.ca/pub/m2</url>
</pluginRepository>
</pluginRepositories>

2. Add the plugin to the product distributions POM

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-buildnumber-plugin</artifactId>
<version>0.9.4</version>
<configuration>
<format>{0,date,dd MMM yyyy}</format>
<items>
<item>timestamp</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>

3. Where ever you use the release date, use the ${buildNumber} property

4. That is it!
Post a Comment