Tuesday, November 8, 2011

Maven Build Number Plugin

For web application usually it's a requirement to pull the latest change set number from source code control and show it up somewhere in application. For the same we can use buildnumber-maven-plugin. To put the plugin in the pom, follow the following XML. Also note that I have tested it with svn only. For others you might want to play with provider implementations.
        <!-- do Check and do update actually talk to repository if it's true,
          Check would check that there are no local changes. Update would update it -->
        <!-- This ensures that even if we are not connected to scm than also take
          the version from local .svn file -->
 <revisionOnScmFailure />
       <!-- will put the entries into META-INF/MANIFEST.MF file -->
The above configuration gives an error that "The scm url cannot be null." This comes even after you have given <revisionOnScmFailure />. To workaround this issue, you need to provide an scm entry in pom.xml as follows

<!-- If you have access to scm then you can place actual url's. Otherwise with
   <revisionOnScmFailure /> you can give some false urls as follows. -->
Once this is done you will see the MANIFEST.MF file containing two entries as Implementation-Version and Implementation-Build. You can read that from the manifest file and inject that into your pages.

No comments:

Post a Comment