Maven release: next development version in batch mode

bergvandenp picture bergvandenp · Mar 18, 2013 · Viewed 11.9k times · Source

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?

Answer

Thomas Keys IV picture Thomas Keys IV · Feb 14, 2018

I know this is a kinda old post but I didn't find an answer I really liked anywhere online and I was able to come up with something that might work well for others...

I wanted to increment the minorVersion as the OP states, and I was able to do so by using a combination of the build helper plugin (to parse the version) and the release plugin, in my project POM. Note the "initialize" phase referenced in the POM and the maven run property...

Here's the excerpt from the POM, we use the build helper plugin to parse the version which we can reference in the release plugin...

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>${maven.build.helper.plugin.version}</version>
                <executions>
                    <execution>
                        <id>parse-versions-for-release</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>parse-version</goal>
                        </goals>
                        <configuration>
                            <propertyPrefix>parsedVersion</propertyPrefix>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>${maven.release.plugin.version}</version>
                <configuration>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <tagNameFormat>@{project.artifactId}-@{project.version}</tagNameFormat>
                    <useReleaseProfile>false</useReleaseProfile>
                    <developmentVersion>${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0-SNAPSHOT</developmentVersion>
                </configuration>
            </plugin>

Now we can just run a pretty normal release, but adding in the "initialize" phase to trigger the version parsing (and ensure it occurs prior to looking for the parsed versions)...

mvn initialize release:clean release:prepare release:perform