I have a multi-module maven project. We intend to version all these modules together. But as of now I am ending up hard-coding version in each of the module pom.xml as below
我有一个多模块的maven项目。我们打算将所有这些模块结合在一起。但是现在,我将在每个模块pom中结束硬编码版本。xml作为下面
<parent>
<artifactId>xyz-application</artifactId>
<groupId>com.xyz</groupId>
<version>2.50.0.g</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz-Library</artifactId>
<version>2.50.0.g</version>
and the main parent module has the below configuration
主父模块的配置如下。
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz-application</artifactId>
<version>2.50.0.g</version>
<packaging>pom</packaging>
7 个解决方案
#1
402
Use versions:set
from the versions-maven plugin:
使用版本:从版本-maven插件中设置:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT
It will adjust all pom versions, parent versions and dependency versions in a multi-module project.
它将在一个多模块项目中调整所有pom版本、父版本和依赖版本。
If you made a mistake, do
如果你犯了错误,就去做。
mvn versions:revert
afterwards, or
之后,或
mvn versions:commit
if you're happy with the results.
如果你对结果满意。
Note: this solution assumes that all modules use the aggregate pom as parent pom also, a scenario that was considered standard at the time of this answer. If that is not the case, go for Garret Wilson's answer.
注意:这个解决方案假设所有模块都使用聚合pom作为父pom,在这个答案的时候,这个场景被认为是标准的。如果情况不是这样,那就去找Garret Wilson的答案吧。
#2
19
You may want to look into Maven release plugin's release:update-versions goal. It will update the parent's version as well as all the modules under it.
您可能想查看Maven版本插件的版本:更新版本的目标。它将更新父版本以及它下面的所有模块。
Update: Please note that the above is the release plugin. If you are not releasing, you may want to use versions:set
更新:请注意上面是发布插件。如果您没有发布,您可能想要使用版本:set。
mvn versions:set -DnewVersion=1.2.3-SNAPSHOT
#3
11
I encourage you to read the Maven Book about multi-module (reactor) builds.
我鼓励您阅读有关多模块(反应器)构建的Maven书籍。
I meant in particular the following:
我的意思是:
<parent>
<artifactId>xyz-application</artifactId>
<groupId>com.xyz</groupId>
<version>2.50.0.g</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz-Library</artifactId>
<version>2.50.0.g</version>
should be changed into. Here take care about the not defined version only in parent part it is defined.
应该改变。这里关心的是定义的父部分中未定义的版本。
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>xyz-application</artifactId>
<groupId>com.xyz</groupId>
<version>2.50.0.g</version>
</parent>
<groupId>com.xyz</groupId>
<artifactId>xyz-Library</artifactId>
This is a better link.
这是一个更好的链接。
#4
4
versions:update-child-modules sounds like what you're looking for. You could do versions:set as mentioned, but this is a light-weight way to update the parent version numbers. For the child modules, it's my opinion that you should remove the <version>
definitions, since they will inherit the parent module's version number.
版本:更新子模块听起来就像您要找的。您可以做版本:如上所述,但这是一种轻量级的方法来更新父版本号。对于子模块,我的观点是您应该删除
#5
4
The given answer assumes that the project in question use project inheritance in addition to module aggregation. In fact those are distinct concepts:
给定的答案假定,除了模块聚合之外,问题中的项目使用项目继承。事实上,这些都是截然不同的概念:
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html Project_Inheritance_vs_Project_Aggregation
Some projects may be an aggregation of modules, yet not have a parent-child relationship between aggregator POM and the aggregated modules. (There may be no parent-child relationship at all, or the child modules may use a separate POM altogether as the "parent".) In these situations the given answer will not work.
有些项目可能是模块的聚合,但是聚合器POM和聚合模块之间没有父子关系。(可能没有父子关系,或者子模块可以使用单独的POM作为“父”。)在这种情况下,给出的答案是行不通的。
After much reading and experimentation, it turns out there is a way to use the Versions Maven Plugin to update not only the aggregator POM but also all aggregated modules as well; it is the processAllModules
option. The following command must be done in the directory of the aggregator project:
经过大量的阅读和实验,我们发现有一种方法可以使用版本Maven插件来更新聚合器POM,也可以更新所有聚合模块;它是processAllModules选项。在聚合器项目的目录中必须执行以下命令:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT -DprocessAllModules
The Versions Maven Plugin will not only update the versions of all contained modules, it will also update inter-module dependencies!!!! This is a huge win and will save a lot of time and prevent all sorts of problems.
这个版本的Maven插件不仅会更新所有包含模块的版本,还会更新模块间的依赖关系!!!!这是一个巨大的胜利,将节省很多时间和防止各种各样的问题。
Of course don't forget to commit the changes in all modules, which you can also do with the same switch:
当然,不要忘记在所有模块中提交更改,您也可以使用相同的切换:
mvn versions:commit -DprocessAllModules
You may decide to dispense with the backup POMS altogether and do everything in one command:
您可以决定放弃所有的备份pom,并在一个命令中做所有的事情:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT -DprocessAllModules -DgenerateBackupPoms=false
#6
2
If you want to fully automate the process (i.e. you want to increment the version number without having to know what the current version number is), you can do this:
如果您想要完全自动化这个过程(例如,您想要增加版本号而不必知道当前版本号是什么),您可以这样做:
mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} versions:commit
#7
1
The best way is, since you intend to bundle your modules together, you can specify <dependencyManagement>
tag in outer most pom.xml
(parent module) direct under <project>
tag. It controls the version and group name. In your individual module, you just need to specify the <artifactId>
tag in your pom.xml
. It will take the version from parent file.
最好的方法是,既然您打算将您的模块捆绑在一起,那么您可以在最外层的pom中指定
#1
402
Use versions:set
from the versions-maven plugin:
使用版本:从版本-maven插件中设置:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT
It will adjust all pom versions, parent versions and dependency versions in a multi-module project.
它将在一个多模块项目中调整所有pom版本、父版本和依赖版本。
If you made a mistake, do
如果你犯了错误,就去做。
mvn versions:revert
afterwards, or
之后,或
mvn versions:commit
if you're happy with the results.
如果你对结果满意。
Note: this solution assumes that all modules use the aggregate pom as parent pom also, a scenario that was considered standard at the time of this answer. If that is not the case, go for Garret Wilson's answer.
注意:这个解决方案假设所有模块都使用聚合pom作为父pom,在这个答案的时候,这个场景被认为是标准的。如果情况不是这样,那就去找Garret Wilson的答案吧。
#2
19
You may want to look into Maven release plugin's release:update-versions goal. It will update the parent's version as well as all the modules under it.
您可能想查看Maven版本插件的版本:更新版本的目标。它将更新父版本以及它下面的所有模块。
Update: Please note that the above is the release plugin. If you are not releasing, you may want to use versions:set
更新:请注意上面是发布插件。如果您没有发布,您可能想要使用版本:set。
mvn versions:set -DnewVersion=1.2.3-SNAPSHOT
#3
11
I encourage you to read the Maven Book about multi-module (reactor) builds.
我鼓励您阅读有关多模块(反应器)构建的Maven书籍。
I meant in particular the following:
我的意思是:
<parent>
<artifactId>xyz-application</artifactId>
<groupId>com.xyz</groupId>
<version>2.50.0.g</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz-Library</artifactId>
<version>2.50.0.g</version>
should be changed into. Here take care about the not defined version only in parent part it is defined.
应该改变。这里关心的是定义的父部分中未定义的版本。
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>xyz-application</artifactId>
<groupId>com.xyz</groupId>
<version>2.50.0.g</version>
</parent>
<groupId>com.xyz</groupId>
<artifactId>xyz-Library</artifactId>
This is a better link.
这是一个更好的链接。
#4
4
versions:update-child-modules sounds like what you're looking for. You could do versions:set as mentioned, but this is a light-weight way to update the parent version numbers. For the child modules, it's my opinion that you should remove the <version>
definitions, since they will inherit the parent module's version number.
版本:更新子模块听起来就像您要找的。您可以做版本:如上所述,但这是一种轻量级的方法来更新父版本号。对于子模块,我的观点是您应该删除
#5
4
The given answer assumes that the project in question use project inheritance in addition to module aggregation. In fact those are distinct concepts:
给定的答案假定,除了模块聚合之外,问题中的项目使用项目继承。事实上,这些都是截然不同的概念:
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html Project_Inheritance_vs_Project_Aggregation
Some projects may be an aggregation of modules, yet not have a parent-child relationship between aggregator POM and the aggregated modules. (There may be no parent-child relationship at all, or the child modules may use a separate POM altogether as the "parent".) In these situations the given answer will not work.
有些项目可能是模块的聚合,但是聚合器POM和聚合模块之间没有父子关系。(可能没有父子关系,或者子模块可以使用单独的POM作为“父”。)在这种情况下,给出的答案是行不通的。
After much reading and experimentation, it turns out there is a way to use the Versions Maven Plugin to update not only the aggregator POM but also all aggregated modules as well; it is the processAllModules
option. The following command must be done in the directory of the aggregator project:
经过大量的阅读和实验,我们发现有一种方法可以使用版本Maven插件来更新聚合器POM,也可以更新所有聚合模块;它是processAllModules选项。在聚合器项目的目录中必须执行以下命令:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT -DprocessAllModules
The Versions Maven Plugin will not only update the versions of all contained modules, it will also update inter-module dependencies!!!! This is a huge win and will save a lot of time and prevent all sorts of problems.
这个版本的Maven插件不仅会更新所有包含模块的版本,还会更新模块间的依赖关系!!!!这是一个巨大的胜利,将节省很多时间和防止各种各样的问题。
Of course don't forget to commit the changes in all modules, which you can also do with the same switch:
当然,不要忘记在所有模块中提交更改,您也可以使用相同的切换:
mvn versions:commit -DprocessAllModules
You may decide to dispense with the backup POMS altogether and do everything in one command:
您可以决定放弃所有的备份pom,并在一个命令中做所有的事情:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT -DprocessAllModules -DgenerateBackupPoms=false
#6
2
If you want to fully automate the process (i.e. you want to increment the version number without having to know what the current version number is), you can do this:
如果您想要完全自动化这个过程(例如,您想要增加版本号而不必知道当前版本号是什么),您可以这样做:
mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} versions:commit
#7
1
The best way is, since you intend to bundle your modules together, you can specify <dependencyManagement>
tag in outer most pom.xml
(parent module) direct under <project>
tag. It controls the version and group name. In your individual module, you just need to specify the <artifactId>
tag in your pom.xml
. It will take the version from parent file.
最好的方法是,既然您打算将您的模块捆绑在一起,那么您可以在最外层的pom中指定