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.2 |
buildnumber | 1.0-beta-1 |
Sample Generated Manifest
Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven Built-By: vsiveton Build-Jdk: 1.5.0_12 SCM-Revision: 613393
Recipe
Configuring Mojo Buildnumber Plugin
We configure this plugin as suggested in the Mojo Buildnumber Plugin usage page.
<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>false</doCheck> <doUpdate>true</doUpdate> </configuration> </plugin>
Configuring Maven Jar Plugin
The last configuration is to customize the default Manifest with a new entry for the SCM revision.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifestEntries> <SCM-Revision>${buildNumber}</SCM-Revision> </manifestEntries> </archive> </configuration> </plugin>
Running Maven
Just call Maven to generate the package:
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.