Quantcast
Viewing latest article 9
Browse Latest Browse All 28

Subversion revision number and build time with Maven

I had this requirement to add the latest build revision from Subversion and the build time to the manifest of the war created using Maven.As I am new to Maven like any other developer I googled for a solution.Though google took me to the right plugin to use, getting the build time turned out to be tricky. Most of the places I found answers which didn't solve the issue.So here is a solution for this, add the below snippets to your POM file.

Step - 1 Add the SVN location


<scm>
 <connection>scm:svn:http://svn.yourlocation/project/trunk</connection>
 <developerConnection>scm:svn:http://svn.yourlocation/project/trunk</developerConnection>
 <tag>HEAD</tag>
 <url>http://svn.yourlocation/project/trunk</url>
</scm>
Step -2 Include the build number maven plugin. This plugin returns the buildnumber as the property buildNumber and build time as the property timestamp. We can refer this anywhere in the POM as ${buildNumber} or {timestamp}. By default the timestamps will be in milliseconds use the  <timestampFormat>{0,date,MM/dd/yyyy hh:mm:ss a}</timestampFormat >to format the timestamp on the format you need.

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0</version>
<executions>
 <execution>
<phase>validate</phase>
<goals>
 <goal>create</goal>
</goals>
 </execution>
</executions>
<configuration>
 <timestampFormat>{0,date,MM/dd/yyyy hh:mm:ss a}</timestampFormat >
 <doCheck>false</doCheck>
 <doUpdate>false</doUpdate>
</configuration>
 </plugin>


Step -3  Include the build version and build time to the manifest using the war or jar plugins.
                     <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
  <archive>
<manifest>
<addDefaultImplementationEntries>true
                                          </addDefaultImplementationEntries>
                                                    </manifest>
<manifestEntries>
 <Revision>${buildNumber}</Revision>
 <Build-Time>${timestamp}</Build-Time>
</manifestEntries>
 </archive> 
                                </configuration>
 </plugin>
  

Having all these three steps will add the SVN revision and the build time to the manifest.

Referece : http://mojo.codehaus.org/buildnumber-maven-plugin/create-mojo.html 

Viewing latest article 9
Browse Latest Browse All 28

Trending Articles