I am trying to update the version in a maven pom.xml
that depends on a parent pom.xml
.
I have /pom.xml
that looks like this
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.burnian</groupId>
<artifactId>parent</artifactId>
<version>14.0.0</version>
<packaging>pom</packaging>
<!-- Plugins & other modules -->
</project>
And the child /child/pom.xml
that looks like this (and is not a module in parent's pom).
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>me.burnian</groupId>
<artifactId>parent</artifactId>
<version>13.0.0</version>
<!-- I've tried <relativePath>../pom.xml</relativePath> with no success -->
</parent>
<artifactId>child</artifactId>
<!-- Again other stuff I think irrelevant here -->
</project>
As you can see, child's pom.xml
refers to version 13.0.0
of parent, which is now version 14.0.0
.
My goal is to update the version in the parent
section to the correct version, using CLI only.
I've tried this sequence of commands which works properly and updates the parent version in the child's pom.xml
:
mvn versions:set -DnewVersion=14.0.0 # To update parent version
mvn clean install # To build parent module with new version
mvn -f child/pom.xml versions:update-parent -DparentVersion="[14.0.0]"
But whenever I try to implement it with -Dmaven.repo.local
, the same process fails.
mvn -Dmaven.repo.local=./.m2/ versions:set -DnewVersion=14.0.0
mvn -Dmaven.repo.local=./.m2/ clean install
mvn -Dmaven.repo.local=./.m2/ -f child/pom.xml versions:update-parent -DparentVersion="[14.0.0]"
The third command fails with Could not find artifact me.burnian.parent:parent:pom:13.0.0 in Proxied-Maven
. I've tried adding -DforceUpdate=true
but since I am not with a RELEASE
or LATEST
version (and can't use one), it has no effect.
Is there something I am missing? I've checked and there is indeed me.burnian
with a parent/14.0.0
folder in the ./.m2
repository, but the last command seems not to find it.
Thanks for your help
CodePudding user response:
That is chicken-egg problem:
in order to update parent version in child/pom.xml
versions:update-parent
need to initialise reactor, but it fails because there is no parent with previous version in local repository. If child were a submodule the versions:update-child-modules
would help, in your case I believe the options are:
- install old version of parent first (
mvn clean install -N
) - modify pom.xml using sed/awk/etc
- create new pom (e.g.
fakepom.xml
) with modulesparent
andchild
and run something like:
mvn -ffakepom.xml versions:set -DnewVersion=${newVersion} --pl parent
mvn -ffakepom.xml versions:update-child-modules