4

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?

  • Your project structure is a bit unusual (the parent could have been placed in the root folder). Can you post the section of artifact1? What happens if you run the plugin from the root folder? – Boj Oct 29 '13 at 00:22
  • I'll do it tomorrow morning PST time. Yes, I agree the folder structure is unusual but I don't have an option to change it since that is out of my control :( If I run the plugin from the root folder it says that the version is derived from the parent and doesn't update any pom. – Maulin Vasavada Oct 29 '13 at 04:12
  • Hi Will, please see my edited post with the pom details. – Maulin Vasavada Oct 29 '13 at 16:51
  • 2
    I resolved it! I forgot to put "parent" in the root/pom.xml :( – Maulin Vasavada Oct 29 '13 at 21:27

3 Answers3

4

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
Mohamed AbdElRazek
  • 1,654
  • 14
  • 17
3

We also had same sort of issue, after debug we found that some of our pom.xml's have the groupId as some variable and not hard coded which was causing issue like below when mvn versions:set runs,

expression: jf.groupId no value

expression: ab.groupId no value

expression: gd.groupId no value

To solve this either modify all pom.xml files to have hard coded groupId and not variable/property or set all these variables as properties in parent/reactor pom.xml

1

I also had this project pom layout and had the same problem, so I'd clarify how I solved it with Maulin's and WIII's help.

I was running versions:set on the root pom.xml, which caused a

[0m[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.1:set (default-cli) on project xxxxxxxxx: Project version is inherited from parent. -> [Help 1]

This I managed to fix by adding a version tag to the root pom.xml. That homever caused only the root to be updated during versions:set, and parent and submodules didn't get the updated version number.

These were fixed by running the versions:set on the parent pom.xml (pom can be specified in jenkins too) and removing version from the root. So only the parent pom had a version and other modules (root and sub-modules) inherited it.

  • 2
    you can run ``mvn versions:set ... -N`` to avoid the "Project version is inherited" problem it tells maven to not run recursively. – adam Nov 01 '15 at 19:25
  • 3
    when you only change the parent pom's version but not the child poms, don't the children still inherit from the old parent pom? Asking because afaiu one has to include the parent pom's version in the child pom, too. – tobi42 May 04 '16 at 12:11