I am working on a Maven project imported under Eclipse Neon which integrates M2Eclipse and therefore the version 3.3.9 of Maven. The sources of my project are managed under SVN 1.6 (yes I know it's old, but we cannot upgrade to 1.7 or 1.8).
I wanted to use the buildnumber-maven-plugin plugin to both retrieve the revision number from the svn repository and generate an incremental build number and then, add them to the Manifest.MF.
After some trials and errors, the pom.xml below does almost what I expect. In fact, everything works fine, except that the buildNumber is not increased sequentially with each build.
For example, it is incremented each time I make a modification in a source file or in the pom.xml itself. Moreover, it is not always increased by 1 each time. I could not find how or when it is incremented.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>3.1.0</version>
<!-- <packaging>jar</packaging>-->
<name>myproject</name>
<url>http://maven.apache.org</url>
<properties>
<subversion.repository>svn://myserversvn/pse/trunk/</subversion.repository>
<redmine.url>https://myredmine:3000/</redmine.url>
<src>src</src>
<src.java>src/java</src.java>
<src.junit>src/junit</src.junit>
<src.resources>src/resources</src.resources>
<target>target</target>
<target.java>target/java</target.java>
<target.junit>target/junit</target.junit>
<target.javadoc>target/javadoc</target.javadoc>
<compileSource>1.8</compileSource>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Specific properties -->
<codaclibs>${project.basedir}/../dependencies/codac-libs</codaclibs>
</properties>
<scm>
<connection>scm:svn:${subversion.repository}/myproject/trunk</connection>
<developerConnection>scm:svn:${subversion.repository}/myproject</developerConnection>
<url>${redmine.url}/projects/pse/repository</url>
</scm>
<build>
<sourceDirectory>${src.java}</sourceDirectory>
<testSourceDirectory>${src.junit}</testSourceDirectory>
<!-- This section is mandatory to avoid an error message in the definition of buildnumber-maven-plugin -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<versionRange>[1.2,)</versionRange>
<goals>
<goal>create</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<!-- First step to get svn revision number as buildNumber -->
<!-- Works only on a machine on which svn is installed (so not on a PC a priori) -->
<execution>
<id>number1</id>
<phase>prepare-package</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>unknown</revisionOnScmFailure>
<timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
</configuration>
</execution>
<execution>
<!-- Second step to compute an incremental number as myBuildNumber -->
<id>number2</id>
<phase>prepare-package</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>svn revision unknown</revisionOnScmFailure>
<buildNumberPropertyName>myBuildNumber</buildNumberPropertyName>
<format>#{0}</format>
<items>
<item>buildNumber</item>
</items>
<timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>${compileSource}</source>
<target>${compileSource}</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<mainClass>${mainclass}</mainClass>
</manifest>
<manifestEntries>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<Build>svn rev ${buildNumber}-build${myBuildNumber} at ${timestamp}</Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<forkMode>always</forkMode>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
...
</dependency>
...
</dependencies>
</project>
Does anybody can tell me the reason of this behavior ? Do you know the different actions which launch the computation of the buildnumber? Any idea to fix that and get a "true" build counter (increased by 1 each time I run the 'Maven install' command)?
FYI if I delete the execution that retrieves the svn revision number ( number1 ), this does not affect the generation of the incremental build number.
Any help would be appreciated great!