Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven release: next development version in batch mode

I have configured a Jenkins job to release my maven project automatically. This is done by using the following: mvn --batch-mode clean release:prepare release:perform In batch mode the release version and the development version will be determined automatically. This is exactly what I want.

The problem is that I want to increase the 2nd number of the version instead of the 3rd one. So when I release version 1.2.0, the next development version must be 1.3.0-SNAPSHOT. Not 1.2.1-SNAPSHOT. Adding a commandline parameter is not an option, because that forces me to constantly edit the build job.

Any suggestions on how to change the algorithm used to determine the next development version?

like image 364
bergvandenp Avatar asked Mar 18 '13 14:03

bergvandenp


People also ask

What is batch mode in Maven release plugin?

This means that the Release Plugin will obtain the required parameters from system properties (set on the command line) or from a properties file ( release.properties ). To prevent the Release Plugin from prompting the user for any information, Maven should be put into batch mode.

Why is the release plugin using batch mode?

Using batch mode with no other configuration will cause the Release Plugin to use default values for the release version, the SCM tag, and the next development version. These values can also be set from the command line.

What is the difference between latest and release in maven2?

Maven2 also provided two special metaversion values to achieve the result: LATEST and RELEASE. LATEST looks for the newest possible version, while RELEASE aims at the latest non-SNAPSHOT version. They're, indeed, still absolutely valid for regular dependencies resolution.

How do I release a Maven project using Jenkins?

I have configured a Jenkins job to release my maven project automatically. This is done by using the following: mvn --batch-mode clean release:prepare release:perform In batch mode the release version and the development version will be determined automatically. This is exactly what I want.


2 Answers

You can use build-helper-maven-plugin. Just add following to pom.xml:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>${maven.build.helper.plugin.version}</version>
    </plugin>

and change command to

mvn --batch-mode clean build-helper:parse-version release:prepare release:perform -DdevelopmentVersion=${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0-SNAPSHOT

(please note that depending on environment you run this command in, you might need to escape $ with \: \$)

like image 175
Krzysztof Kosmatka Avatar answered Sep 23 '22 13:09

Krzysztof Kosmatka


There is a parameter projectVersionPolicyId provided in the release:prepare mojo: http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#projectVersionPolicyId

There might not be built-in version policy to satisfy your needs, but you can develop your own version policy by implementing the interface VersionPolicy. You can see maven-release-yearly-policy as a reference, which provided a version policy using year in the version numbers.

like image 36
johnlinp Avatar answered Sep 25 '22 13:09

johnlinp