How to use Apache maven buildnumber plugin

How to use Apache maven buildnumber plugin

Here we are going to see the usage of Build Number Maven Plugin. This plugin could be used to generated unique build numbers for the artifacts generated using maven. I have generated a sample project using maven with groupId, artificatId, version and packaging information.

Step1: Generate the sample quickstart project.

Generate maven project
mvn archetype:generate

Here are the sample project coordinates that i used

groupId - com.maven.apache
artifactId - buildnumbertest
version - 1.0
packaging - jar
The default maven project would contain the below pom.xml file

Step2: Install the project to local repository with below command

Install maven project to local repository
mvn install

This will generate the artifact with groupId and version number as below

buildnumtest-1.0

Step3: Edit pom.xml to generate unique buildnumbers for this maven project appending date and time

Step4: Run mvn install now to generate the artifact with below format name

Run maven install with build number plugin
buildnumtest-1.0-r2014-09-30-081925
buildnumtest-1.0-r2014-09-30-082052

This plugin would be very useful when to differentiate between multiple 

builds for a particular version of the project.

Hope you enjoyed reading this article. Thank you.