2013-11-15

Maven build timestamp

Want to display a Maven build timestamp using a Maven build. Check this out...

Create a file in src/main/resources. Its name can be whatever.properties. 
It could contain:
   the.application.version     = ${project.version}
   the.application.build.time  = ${maven.project.timestamp}

Then, in the pom.xml, you should have in the build tag:
<resources>
   <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
   </resource>
</resources>

The filtering to true is the magic that converts ${project.version} to the real deal project version.

We could've used maven.build.timestamp in the whatever.properties file, instead of maven.project.timestamp, which is not a Maven standard property. 
But, there is a bug in Maven. The workaround is to use it indirectly as in the pom.xml, properties tag:
<maven.project.timestamp>${maven.build.timestamp}</maven.project.timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>

That's pretty it.


No comments: