Use mvn version plugin during mvn release

712 Views Asked by At

I have a multi-module maven project in Kubernates. We intend to version all these modules together. But as of now, I end up hard-coding version in each of the module pom.xml as below

<parent>
    <artifactId>xyz-application</artifactId>
    <groupId>com.xyz</groupId>
    <version>2.50.0.g</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz-Library</artifactId>
<version>2.50.0.g</version>

The main parent module has the below configuration

<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz-application</artifactId>
<version>2.50.0.g</version>
<packaging>pom</packaging>

Reference

Currently, I'm using the mvn release plugin in the pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.3</version>
    <configuration>
        <autoVersionSubmodules>true</autoVersionSubmodules>
        <tagNameFormat>${product_label}-@{project.version}</tagNameFormat>
        <releaseProfiles>releases</releaseProfiles>
        <preparationGoals>clean deploy</preparationGoals>
        <arguments>-s settings.xml</arguments> 
    </configuration>
</plugin>

Since the project is in Kubernetes, here is the Jenkins file content I'm using while the release

def MVN_RELEASE = "release:clean release:prepare release:perform -Dmaven.source.skip=true"
stage('Release artifacts to artifactory') {
    steps {
        container('maven') {
            withCredentials() {
                sh "mvn ${MVN_RELEASE}  -Dresume=false"
            }
        }
    }
}

Now, during release, I need to update the parent pom and all sub-modules poms version by a new version of my choice, I can use a mvn version plugin, something like

  1. mvn versions:set -DnewVersion=3.00.0-SNAPSHOT -DprocessAllModules -DgenerateBackupPoms=false and then
  2. mvn versions:commit -DprocessAllModules

At what stage in Jenkins/pom.xml should I add this? Now, this plugin is useful only when I want to bump to a specific version of my choice (like 3.00.0-Snapshot), otherwise, the mvn release plugin should bump the version automatically to something like 2.50.1-SNAPSHOT. Is that correct understanding?

How can I gracefully handle this pom version update issue?

Thanks in advance!

1

There are 1 best solutions below

23
On

I do not see why you want the version plugin.

First of all, you don't need to add the <version> tag to the modules. You need to specify the version of the parent, but you can inherit your version (which is the same) from the parent.

Secondly, the maven release plugin has parameters releaseVersion and developmentVersion which allow you to set a release and future development version on the command line.