logo Build Number Maven Plugin

This plugin is designed to give you a build number. So when you might make 100 builds of version 1.0-SNAPSHOT, you can differentiate between them all.

homepage: www.mojohaus.org/buildnumber-maven-plugin
fresh index:
last release: 2 months ago, first release: 1 decade ago
packaging: maven-plugin
get this artifact from: central
see this artifact on: search.maven.org


Display vulnerabilities (snyk): Vulnerability check

This chart shows how much is this artifact used as a dependency in other Maven artifacts in Central repository and GitHub:


select version:

Add this snippet into pom.xml inside tag <project><build><plugins>:




Switch to artifact.
goals:
buildnumber:create (phase: initialize)

This mojo is designed to give you a build number. So when you might make 100 builds of version 1.0-SNAPSHOT, you can differentiate between them all. The build number is based on the revision number retrieved from SCM. It is known to work with Subversion, GIT, and Mercurial. This mojo can also check to make sure that you have checked everything into SCM, before issuing the build number. That behaviour can be suppressed, and then the latest local build number is used. Build numbers are not automatically reflected in your artifact's filename, but can be added to the metadata. You can access the build number in your pom with ${buildNumber}. You can also access ${timestamp} and the SCM branch of the build (if applicable) in ${scmBranch} Note that there are several doFoo parameters. These parameters (doCheck, doUpdate, etc) are the first thing evaluated. If there is no matching expression, we get the default-value. If there is (ie -Dmaven.buildNumber.doUpdate=false), we get that value. So if the XML contains <doCheck>true</doCheck>, then normally that's the final value of the param in question. However, this mojo reverses that behaviour, such that the command line parameters get the last say.

buildnumber:create-metadata (phase: generate-resources)

This mojo discovers latest SCM revision, current timestamp, project version, and project name then write them to one or more java property files together with a set of user provided properties. It also has option to add the output file to resource classpath for jar packaging.

buildnumber:create-timestamp (phase: initialize)

This mojo is designed to give you a timestamp available through one or more properties. Only a single timestamp is created for each execution of the mojo. This timestamp can be format into one or more strings which are then saved to properties. create a timestamp property

buildnumber:help

Display help information on buildnumber-maven-plugin. Call mvn buildnumber:help -Ddetail=true -Dgoal=<goal-name> to display parameter details.

buildnumber:hgchangeset (phase: initialize)

Goal which sets project properties for changeSet and changeSetDate from the current Mercurial repository.

Often used code snippets:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>buildnumber-maven-plugin</artifactId>
  <configuration>
    <format>{0,date,dd MMM yyyy}</format>
    <items>
      <item>timestamp</item>
    </items>
    <doCheck>false</doCheck>
    <doUpdate>false</doUpdate>
  </configuration>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>buildnumber-maven-plugin</artifactId>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>buildnumber-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>build-identity</id>
      <phase>initialize</phase>
      <goals>
        <goal>create</goal>
      </goals>
      <configuration>
        <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
        <buildNumberPropertyName>build.revision</buildNumberPropertyName>
        <scmBranchPropertyName>build.branch</scmBranchPropertyName>
        <timestampPropertyName>build.when</timestampPropertyName>
        <timestampFormat>{0,date,yyyy-MM-dd-HHmm-ssS}</timestampFormat>
      </configuration>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>buildnumber-maven-plugin</artifactId>
  <version>1.2</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <doCheck>false</doCheck>
    <doUpdate>false</doUpdate>
  </configuration>
</plugin>
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>buildnumber-maven-plugin</artifactId>
  <version>1.4</version>
  <executions>
    <execution>
      <phase>initialize</phase>
      <goals>
        <goal>create</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
    <providerImplementations>
      <git>git</git>
    </providerImplementations>
    <doCheck>false</doCheck>
    <doUpdate>false</doUpdate>
  </configuration>
</plugin>

© Jiri Pinkas 2015 - 2022. All rights reserved! Admin login To submit bugs / feature requests please use this github page
related: JavaVids | Top Java Blogs | Java školení
Apache and Apache Maven are trademarks of the Apache Software Foundation. The Central Repository is a service mark of Sonatype, Inc.