mavenmaven-3

How to force an arbitrary parent version when using mvn versions:update-parent?


(Rephrasing the question to give a better understanding) To elaborate on my issue which wasn't detailed enough, these are the following cases I encountered: projects: A and B. The root pom of A is the parent of project B.

Because of some constraints to our release process (this is to give some current context, but this should not be taken as the main drive to circumvent the issue at hand) , I need to change the version of both projects.

If I change the version of A, then change the version of B, I get the following error message:

mvn versions:update-parent -DallowSnapshots -DgenerateBackupPoms=false -DparentVersion="6.4.1-SNAPSHOT" 
[WARNING] Not updating version: could not resolve any versions

If I change the version of A, call mvn clean install on A (which I could live with, although I would prefer to be able to change the version and parent of all my projects at once, in scripts, without intermediate, possibly-failing, builds), then the above command on B works but only if the specified parent version is the latest available. Otherwise I get:

[INFO] Current version of parentGroup:parentArtifact:pom:7.0.12 is the latest.

Which means I cannot use the mvn versions:update-parent command to change the parent version on maintenance branch.

Is there a way to make mvn versions:update-parent respect the required parent version? (regardless of whether it can be found locally, on the nexus repository or not yet at all)


edit: additional info with -X (removed irrelevant parts, emphasis mine)

[DEBUG] Configuring mojo 'org.codehaus.mojo:versions-maven-plugin:2.5:update-parent' with basic configurator -->
[DEBUG]   (f) allowSnapshots = true
[DEBUG]   (f) generateBackupPoms = false
(...)
[DEBUG]   (f) parentVersion = 7.0.11
[DEBUG] Determining update check for artifact groupId:artifactIdProjectA (C:\Users\donckels\.m2\repository\.......\artifactIdProjectA\maven-metadata-....-repository.xml) from ....-repository (http://..../nexus/content/groups/public)
(....)
[DEBUG] Searching for ....-repository.maven-metadata-....-repository.xml.lastUpdated in resolution tracking file.
[DEBUG] Reading resolution-state from: C:\Users\donckels\.m2\repository\.....\artifactIdProjectA\resolver-status.properties
(....)
[DEBUG] Proposal is to update from 7.0.12 to 7.0.12
[INFO] Current version of groupId:artifactIdProjectA:pom:7.0.12 is the latest.

Even though I specified 7.0.11, it ends up with:

[DEBUG] Proposal is to update from 7.0.12 to 7.0.12

Solution

  • Provided the parent version has been built before, this syntax (with the square brackets around the version number) allows to force a version which is not the latest:

    mvn versions:update-parent -DallowSnapshots -DgenerateBackupPoms=false -DparentVersion="[7.0.11]" 
    

    But the parent has to be built before maven makes the update. Otherwise it will ignore the specified version.