You want to create a build number in the web front end of your application (e.g. to have it on screenshots appended to bug reports during user acceptance test).
You are using maven for your builds and your code is under source control (e.g. using subversion).
All you need is some maven plugins and a place to write the build number to.
In this case I’d like to have the maven version number followed by the subversion revision number and a timestamp of the build date like this:
Version: 1.0-SNAPSHOT r1 Built on: 2012-02-19 13:41
First I create a version.html in src/main/resources or src/main/templates or something like that:
<div class="version">Version: @VERSION@</div> <div class="builton">Built on: @BUILTON@</div>
As you can see there are two placeholders (@VERSION@ and @BUILTON@)
Next I insert and configure the plugins to create the version info and the timestamp and to replace the placeholders with them in my pom.xml:
This creates a property named buildNumber with the revision number of the checked out code. The configuration doCheck=true causes a check whether there are any uncommitted changes. If there were any, the build would fail. With doUpdate you could instruct the build to execute a svn update prior to execution of the build.
For more info about this plugin see here:
We could also use this plugins goal “create-timestamp” to create the timestamp, but since maven itself provides a property for that we just need to set that properties format in the properties section of our pom:
Now having all we need, we need to replace the placeholders in our html and copy the replacement to our target folder.
This replaces the placeholders in src/main/templates/version.html with the values and writes the result into the specified target folder.
More info about this plugin is provided here:
Having that, you just need to include that into your pages. That’s it.
We now have a build number on our pages.
There for sure is room to improve this solution and it is for sure not the only solution. But it did the job for me and I hope it will help you.
If I should have forgotten something in this description, do not hesitate to give me feedback via the comments form.