How to use Apache maven buildnumber plugin

How to use Apache maven buildnumber plugin

apache_maven_buildnumber_plugin_usage

Here in this artcle we will use the Apace maven buildnumber plugin to update the artifact with the appropriate format build number.

Test Environment

Apache maven

Build Number Maven Plugin

This plugin could be used to generated unique build numbers for the artifacts generated using maven.

Procedure

Step1: Generate the sample quickstart project

Here let’s generate a sample project using maven with groupId, artificatId, version and packaging information.

mvn archetype:generate

Here are the sample project coordinates that i used.

groupId - com.maven.apache
artifactId - buildnumbertest
version - 1.0
packaging - jar

Step2: Install the project to local repository with below command

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

Here is the plugins section which needs to be updated with the “buildnumber-maven-plugin” as shown below.

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>create-timestamp</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <timestampFormat>yyyy-MM-dd-HHmmss</timestampFormat>
          <timestampPropertyName>build.time</timestampPropertyName>
        </configuration>
      </plugin>
    </plugins>
    <finalName>${project.artifactId}-${project.version}-r$(build.tme)</finalName>
  </build>

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

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.