I have the below configuration to create a build number and save it in the MANIFEST.MF. The build process generates a buildNumber.properties and keeps track of the last build from it. However this file I assume should be committed back into GIT as a part of storing the buildNumber. Is this understanding correct? or is there any other way to achieve this?
build goal
mvn clean package
pom.xml
<scm>
<connection>scm:git:https://abc.xyz.com/#projects/scm/DOCKER-AbcServer.git</connection>
</scm>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,number}</format>
<items>
<item>buildNumber0</item>
</items>
<doCheck>true</doCheck>
<doUpdate>true</doUpdate>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Number>${project.version}-r${buildNumber}</Build-Number>
<Build-SCMBranch>${scmBranch}</Build-SCMBranch>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
buildNumber.properties
#maven.buildNumber.plugin properties file
#Fri Aug 10 10:49:49 PDT 2018
buildNumber0=2
If you commit your buildNumber.properties file you would get a build number that increments between each developer and continuous-integration builde EXCEPT if you build in your checkout and someone else does their build. You'll both increment the build number. When one of you commits the file and pushes, which one of you wins? What is the current build number for the project?
I think it is more accurate to think of an incremental build number as "a build number for a particular clone" rather than one that is constant across the whole project.
If you use git or svn or any other SCM that buildnumber is integrated with, you can use the SCM commit id as a build number instead of an integer. This is inherently stored by the SCM and shows exactly what commit a build was made from. I prefer this because by looking at a manifest file or JAR name I can immediately jump to the right commit to triage an issue or determine if a user is using an outdated build.
Another good question covers some details of the buildnumber plugin and provides additional resources: Maven build number plugin, how to save the build number in a file?