Cookbook: How To Add SVN Revision To A JAR Manifest?

Summary

This recipe describes how to add SVN revision to a JAR manifest.

Prerequisite Plugins

Here is the list of the plugins used:

Plugin Version
jar 2.6
buildnumber 1.3

Sample Generated Manifest

  1. Manifest-Version: 1.0
  2. Archiver-Version: Plexus Archiver
  3. Created-By: Apache Maven
  4. Built-By: vsiveton
  5. Build-Jdk: 1.5.0_12
  6. SCM-Revision: 613393

Recipe

Configuring Mojo Buildnumber Plugin

We configure this plugin as suggested in the Mojo Buildnumber Plugin usage page.

  1. <plugin>
  2. <groupId>org.codehaus.mojo</groupId>
  3. <artifactId>buildnumber-maven-plugin</artifactId>
  4. <executions>
  5. <execution>
  6. <phase>validate</phase>
  7. <goals>
  8. <goal>create</goal>
  9. </goals>
  10. </execution>
  11. </executions>
  12. <configuration>
  13. <doCheck>false</doCheck>
  14. <doUpdate>true</doUpdate>
  15. </configuration>
  16. </plugin>

Configuring Maven Jar Plugin

The last configuration is to customize the default Manifest with a new entry for the SCM revision.

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-jar-plugin</artifactId>
  4. <configuration>
  5. <archive>
  6. <manifestEntries>
  7. <SCM-Revision>${buildNumber}</SCM-Revision>
  8. </manifestEntries>
  9. </archive>
  10. </configuration>
  11. </plugin>

Running Maven

Just call Maven to generate the package:

  1. mvn package

Note: You need to have committed your project into SVN.

Other Tips

You could tweak the Jar Plugin configuration into the War Plugin.