Maven uppdate version of module and dependencies i

2019-08-16 05:39发布

问题:

I'm struggling with updating version of module. My project is huge (around 50 modules) but I will simplify it for an example purpouse.

-moduleA
  -moduleA1
    -pom.xml
  -pom.xml
-moduleB
  -moduleB1
    -pom.xml
  -pom.xml
-pom.xml

What I want to do. Lets's assume one version in every pom.xml - 5.0.0. ModuleA1 pomx looks like:

<parent>
    <groupId>com.sample.project</groupId>
    <artifactId>moduleA</artifactId>
    <version>5.0.0</version>
</parent>
<groupId>com.sample.project.moduleA</groupId>
<artifactId>moduleA1</artifactId>
<version>5.0.0</version>

Now I want to increase version of moduleA1. So...

mvn -N versions:set -DnewVersion=5.0.1 -DgroupId=com.sample.project.moduleA -DartifactId=moduleA1

ModuleB1 has dependency to moduleA1

<parent>
    <groupId>com.sample.project</groupId>
    <artifactId>moduleB1</artifactId>
    <version>5.0.0</version>
</parent>
<groupId>com.sample.project</groupId>
<artifactId>moduleB1</artifactId>
<version>5.0.0</version>
<dependency>
        <groupId>com.sample.project.moduleA</groupId>
        <artifactId>moduleA1</artifactId>
        <version>5.0.0</version>
</dependency>

Version of this dependency should be updated and it is but only for the first time *when version is the same as parent). If I want to update it to 5.0.2 this dependency will not be changed it will stay 5.0.1 (only pointed moduleA1 will be updated to 5.0.2) I tried to use dependencyManegement but the result was exactly the same. Any ideas how to force maven to update pointed module and dependencies of its module on other modules?

回答1:

Use ${project.version} in all module dependencies and you have consistent and up to date versions.



回答2:

Finally I found the solution. The key is to set oldVersion parameter to the previous version. Otherwise version:set will use ${project.version} and that's way updating version work for the first time because module version is the same as project.version.