Version & build timestamp in Manifest with maven
I blogged about reading a jar’s manifest file recently but what use is reading a manifest unless it contains something useful. In a development environment where we are constantly pushing SNAPSHOT’s to others, it helps to know what version of your code base others are using in order to debug problems.
Two properties here are especially useful, the version of your jar and the time it was built. To include these through maven, you must use the maven jar plugin to add the properties to your jar’s manifest at build time.
The configuration is simple, in the build section of your pom.xml add the following plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<addMavenDescriptor />
<manifest>
<addDefaultImplementationEntries />
<addDefaultSpecificationEntries />
</manifest>
<manifestEntries>
<ComponentVersion>${project.version}</ComponentVersion>
<BuildTime>${maven.build.timestamp}</BuildTime>
</manifestEntries>
</archive>
</configuration>
</plugin>
And that’s it. You’re done.
I believe it would also be useful to add the revision number of the build but I haven’t quite figured out how to do that yet, so that’s for another time.








