How to add a version number to your maven webapp

I couldn’t find a simple recipe to add a version number to a maven-built webapp. The maven-war-plugin talks about how to filter, but no simple example is given.

So. I’ll assume you are building your webapp with hudson, that you’re using subversion, and that your webapp has some text file(s) (.html or .jsp, perhaps?) in src/main/webapp that are a good place to display your version number.

  1. Add a “display_version” to your maven properties:

    Note that hudson will fill in the SVN_REVISION value for you. If you want some other number from the build in your version, you can use other hudson variables, but cook the version number to your taste.

  2. Configure the maven-war-plugin to enable filtering:

    (Note that the nonFilteredFileExtension prevents binary file corruption. It was added in the maven-war-plugin 2.1-alpha-2.)

  3. Finally, Insert ${display_version} into your webapp:
    I had a jsp/html file that had a footer with a copyright notice that was a nice place to append a version stamp:

Run mvn war:exploded or mvn package to try it out.

Update December 14, 2009:

Note that Hudson’s SVN_REVISION macro is empty if you build your project as a maven multi-module. Use one of the other hudson macros in your display_version instead.

Posted in Technical HOWTOs Tagged with: , ,
  • Martin Groenhof

    THx dude

  • Benny Neugebauer

    Thank you for your post! It has been very helpful! 🙂

  • I just configured as above, but I am seeing $(project.version) in the html viewed in browser. Why isn’t project.version expanded? Anyother configuration to be made?