Skip to content

Instantly share code, notes, and snippets.

@michl-b
Created August 23, 2018 09:28
Show Gist options
  • Save michl-b/65797f4b38751c0f7eae678b99b4a3d4 to your computer and use it in GitHub Desktop.
Save michl-b/65797f4b38751c0f7eae678b99b4a3d4 to your computer and use it in GitHub Desktop.
increment project version by maven profile
<profiles>
<profile>
<id>incrementVersion</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>parse-version</id>
<phase>validate</phase>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>run</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Major: ${parsedVersion.majorVersion}</echo>
<echo>Minor: ${parsedVersion.minorVersion}</echo>
<echo>Incremental: ${parsedVersion.incrementalVersion}</echo>
<echo>Qualifier: ${parsedVersion.qualifier}</echo>
<echo>BuildNumber: ${parsedVersion.buildNumber}</echo>
<echo>nextMajorVersion: ${parsedVersion.nextMajorVersion}</echo>
<echo>nextMinorVersion: ${parsedVersion.nextMinorVersion}</echo>
<echo>nextIncrementalVersion: ${parsedVersion.nextIncrementalVersion}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>set</id>
<phase>validate</phase>
<goals>
<goal>set</goal>
</goals>
<configuration>
<newVersion>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}</newVersion>
</configuration>
</execution>
<execution>
<id>commit</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
@michl-b
Copy link
Author

michl-b commented Aug 23, 2018

increment the version by
mvn validate -P incrementVersion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment