I am a new user of Maven, and am having difficulty getting the buildnumber-maven-plugin to do what I expect. Essentially, I want maven to build my project and create a JAR file of the result, and to set a build number in the manifest.mf file. I'll include most of my pom.xml file below. I've posted a related question already, but this question is about a different problem!
When I run mvn clean compile package I see the following error:
[ERROR] Failed to execute goal org.codehaus.mojo:buildnumber-maven-plugin:1.4:create (buildnumber) on project xcase: Execution buildnumber of goal org.codehaus.mojo:buildnumber-maven-plugin:1.4:create failed: The scm url cannot be null. -> [Help 1]
I have set both doCheck and doUpdate to false, so don't know why the SCM is involved. My workaround has been to add some dummy SCM configuration, but this feels clunky. Is there a better way?
<scm>
<connection>scm:svn:http://127.0.0.1/dummy</connection>
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
<tag>HEAD</tag>
<url>http://127.0.0.1/dummy</url>
</scm>
Here is the build section of my pom.xml file:
<build>
<outputDirectory>build</outputDirectory>
<plugins>
<plugin>
<artifactId>buildnumber-maven-plugin</artifactId>
<configuration>
<buildNumberPropertyName>buildNumber</buildNumberPropertyName>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<format>{0,number,integer}</format>
<items>
<item>buildNumber</item>
</items>
<revisionOnScmFailure>true</revisionOnScmFailure>
</configuration>
<executions>
<execution>
<goals>
<goal>create</goal>
</goals>
<id>buildnumber</id>
</execution>
</executions>
<groupId>org.codehaus.mojo</groupId>
<version>1.4</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/build</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<filtering>true</filtering>
<excludes>
<exclude>*local*.properties</exclude>
</excludes>
<includes>
<include>*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/java</directory>
<filtering>true</filtering>
<includes>
<include>log4j2.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
<sourceDirectory>src/java</sourceDirectory>
</build>
According to the buildnumber:create docs this plugin is especially created to work with SCM:
The build number is based on the revision number retrieved from SCM. It is known to work with Subversion, GIT, and Mercurial.
So to accomplish your intention you should NOT use this plugin and need to use a different approach instead.
Default maven installation offers some special variables, among them a variable named maven.build.timestamp, which gives you a timestamp. You can control the format with
<properties>
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
</properties>
which follows the SimpleDateFormat rules. You can use ${maven.build.timestamp} to get a formatted timestamp for your build number.
Configure default value for local builds:
<properties>
<buildNumber>0</buildNumber>
<properties>
In CI explicitly provide this value through command line:
./mvnw clean deploy -DbuildNumber=...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With