1

Suppose I have a multi-module maven project, with a parent pom:

<project>
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.example</groupId>
  <artifactId>my-parent</artifactId>
  <version>0.1.0</version>

  <modules>
    <module>module1</module>
    <module>module2</module>
    <!-- etc. -->
  </modules>
</project>

and several modules like:

<project>
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.example</groupId>
  <artifactId>module1</artifactId>
  <version>0.1.0</version>

  <parent>
    <groupId>com.example</groupId>
    <artifactId>my-parent</artifactId>
    <version>0.1.0</version>
  </parent>
</project>

Now I am trying to update the version of the parent pom using the versions maven plugin, without updating the corresponding parent section in the child modules. That is, I want the parent to get a version of e.g. 0.2.0-SNAPSHOT, while the child modules still refer to the 0.1.0 parent version in this example, i.e.:

<project>
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.example</groupId>
  <artifactId>module1</artifactId>
  <version>0.1.0</version>

  <parent>
    <groupId>com.example</groupId>
    <artifactId>my-parent</artifactId>
    <version>0.1.0</version>
  </parent>
</project>

How can I do this?

I have tried just about every optional parameter for the mvn versions:set command that seemed like it could affect this behavior, including the maven -N flag, in various combinations, but none of them worked. Is it possible to do this with the versions maven plugin? Is there some other way?

It seems like I am having the opposite problem as described in these questions:

Versions plugin not updating child modules, just parent being updated

versions-maven-plugin on mutli module project with aggregator pom does not set versions on modules

Note that I am trying to automate this task, which is why I would to run some plugin/command to achieve the desired result (manually you can obviously just edit the relevant line in the parent pom).

Johan
  • 477
  • 4
  • 8

1 Answers1

0

The correct way to do this is to use branching in your version control system (e.g. git).

Let's assume you work on branch develop with the 0.1.0 version.

  1. merge your develop branch to master. The master branch is now 0.1.0
  2. check out your develop branch again.
  3. upgrade the project on develop branch to 0.2.0-SNAPSHOT
  4. if you need to point to the 0.1.0 version of any artifact, you can do that now.

Now, your master branch has 0.1.0, and the 0.1.0 artifacts exist in your local maven repository.

The develop branch has version 0.2.0-SNAPSHOT.

vikingsteve
  • 38,481
  • 23
  • 112
  • 156
  • Thanks for the suggestion, but it's not really what I'm looking for. I understand I can use multiple branches, but I would rather not because I'm trying to run it in an automated pipeline and it creates the possibility for a conflict that has to be manually resolved. Especially because the different modules may get updated simultaneously, but independently. – Johan Apr 20 '23 at 06:51