0

I want to have a build number for my maven project.

I used the following configuration in pom.xml:

        <!-- build number -->
        <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>
             <doCheck>false</doCheck>
             <doUpdate>false</doUpdate>
           </configuration>
        </plugin>
    </plugins>
    <finalName>${project.artifactId}-${project.version}-r${buildNumber}</finalName>
</build>
<!-- dummy scm for build number plugin -->
<scm>
   <connection>scm:git:http://127.0.0.1/dummy</connection>
   <developerConnection>scm:git:https://127.0.0.1/dummy</developerConnection>
   <tag>HEAD</tag>
   <url>http://127.0.0.1/dummy</url>
</scm>

I did this expecting that it would store a build number somewhere, and that it would increase it with every build. But what it does is to use the git commit handle as the build number.

Is it possible to get the build number plugin to work like I want? Or is there a different plugin which does what I want? Or should I just accept the working of the build number plugin because using the git commit handle as build number is in my best interest?

Adder
  • 5,708
  • 1
  • 28
  • 56
  • The finalName will only work for the `target` directory but not if you do `mvn install` or `mvn deploy` ... – khmarbaise Mar 04 '20 at 17:14
  • I don't see the problem, calling `mvn install` from the IDE creates the target directory and a war file in it. I haven't used `mvn deploy` yet. – Adder Mar 04 '20 at 17:18
  • In the target directory yes but not in your local repository $HOME/.m2/. ... – khmarbaise Mar 04 '20 at 18:05

1 Answers1

0

I changed the pom.xml build number configuration like this, adding a <format>:

        <!-- build number -->
        <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>buildNumber</item>
             </items>
             <doCheck>false</doCheck>
             <doUpdate>false</doUpdate>
           </configuration>
        </plugin>
    </plugins>
    <finalName>${project.artifactId}-${project.version}-r${buildNumber}</finalName>
</build>
<!-- dummy scm for build number plugin -->
<scm>
   <connection>scm:git:http://127.0.0.1/dummy</connection>
   <developerConnection>scm:git:https://127.0.0.1/dummy</developerConnection>
   <tag>HEAD</tag>
   <url>http://127.0.0.1/dummy</url>
</scm>

It now works as intended by me and stores the build number in buildNumber.properties.

I got this idea from automatically incrementing a build number in a java project

Adder
  • 5,708
  • 1
  • 28
  • 56