Tuesday, September 16, 2008

How to use formated maven2 timeStamp and buildNumber using buildnumber-maven-plugin mojo?

Today I was wondering how to use a formatted build timestamp and the current svn build version in your maven pom using the buildnumber-maven-plugin mojo, as most of the postings I found say it doesnt work. But it does. Read on.

The trick is to use two execution sections, one for the buildNumber (the current svn version) and another one for the formated timestamp, but this time we store the value in a new property called buildTimestamp.

With this, you can use the two properties ${buildNumber} and ${buildTimestamp} wherever you want.
Tip: Define the plugin in the main pom.xml file. It gets executed in every maven sub module.


<plugins>
<plugin>
<groupid>org.codehaus.mojo</groupid>
<artifactid>buildnumber-maven-plugin</artifactid>
<executions>
<execution>
<!-- buildNumber -->
<id>generate-buildNumber</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<docheck>false</docheck>
<doupdate>false</doupdate>
</configuration>
</execution>
<execution>
<!-- buildTimestamp -->
<id>generate-timestamp</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<format>{0,date,yyyy-MM-dd_HH-mm}</format>
<items>
<item>timestamp</item>
</items>
<docheck>false</docheck>
<doupdate>false</doupdate>
<buildnumberpropertyname>buildTimestamp</buildnumberpropertyname>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

No comments:

Post a Comment

Due to the high amount of Spam, you must solve a word verification.