mvn versions:set not updating child poms

Maulin Vasavada picture Maulin Vasavada · Oct 28, 2013 · Viewed 9k times · Source

I did much research on this but could not resolve it so far.

I've following structure,

root folder
parent/pom.xml (parent pom)
artifact1/pom.xml
artifact2/pom.xml
pom.xml (aggregator pom)

root/pom.xml
------------

<parent>
    <groupId>releasetest2</groupId>
    <artifactId>root</artifactId>
    <version>1.0.4</version>
    <relativePath>parent</relativePath>
</parent>

<artifactId>aggregator</artifactId>
<packaging>pom</packaging>


artifact1/pom.xml
-----------------

<parent>
    <groupId>releasetest2</groupId>
<artifactId>root</artifactId>
<version>1.0.4</version>
<relativePath>../parent</relativePath>
</parent>

<groupId>releasetest</groupId>
<artifactId>artifact1</artifactId>
<packaging>jar</packaging>


artifact2/pom.xml
-----------------

<parent>
<groupId>releasetest2</groupId>
<artifactId>root</artifactId>
<version>1.0.4</version>
<relativePath>../parent</relativePath>
</parent>

<groupId>releasetest</groupId>
<artifactId>artifact2</artifactId>
<packaging>jar</packaging>


parent/pom.xml
--------------

<groupId>releasetest2</groupId>
<artifactId>root</artifactId>
<version>1.0.4</version>
<packaging>pom</packaging>

<properties>
    <MAIN.version>${project.version}</MAIN.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
              <groupId>releasetest</groupId>
              <artifactId>artifact1</artifactId>
            <version>${MAIN.version}</version>
        </dependency>
        <dependency>
            <groupId>releasetest</groupId>
            <artifactId>artifact2</artifactId>
            <version>${MAIN.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

When I use mvn versions:set while being in parent folder it only updates the parent/pom.xml. I expected it to update root/pom.xml artifact1/pom.xml and artifact2/pom.xml

Is there a way to resolve this?

Answer

Mohamed AbdElRazek picture Mohamed AbdElRazek · Jun 4, 2019

First please revert version number in the parent pom and make sure that all child poms have the same version.

Then navigate to parent pom directory and execute this command :

mvn versions:set versions:update-child-modules -DnewVersion=<New_Version_Number> -DprocessAllModules