java 更新 Maven 项目模块中的父版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39449275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update parent version in a maven project's module
提问by Sandy
I've a strange scenario where I have a project "Y" and it has a module "X" and some other modules as well.
我有一个奇怪的场景,我有一个项目“Y”,它有一个模块“X”和其他一些模块。
X is part of a project Y however it is not linked as a module of that project. Because of that, each time a newer version of Y is released someone needs to manually update the parent version in X.
X 是项目 Y 的一部分,但它并未链接为该项目的模块。因此,每次发布新版本的 Y 时,都需要有人手动更新 X 中的父版本。
I need to update the Y project in such a way that: a)each time the Y project is released, the parent project version in X should be automatically updated by TeamCity (in a similar way as for other modules)
我需要以这样的方式更新 Y 项目:a) 每次发布 Y 项目时,X 中的父项目版本应由 TeamCity 自动更新(与其他模块类似)
b)X must not be a part of Y distribution
b) X 不能是 Y 分布的一部分
c)Once deployed in TeamCity, it should not run tests from X (they should be run with Integration tests and Release builds)
c) 一旦部署在 TeamCity 中,它就不应该从 X 运行测试(它们应该与集成测试和发布版本一起运行)
回答by alexbt
versions:update-parent
版本:更新父
If you open a terminal at the root of your project X
, you can use versions:update-parent
to update its parent version to the latest
:
如果您在项目的根目录打开终端X
,您可以使用versions:update-parent
将其父版本更新为latest
:
$ mvn versions:update-parent -DallowSnapshots=true
You can execute this command from TeamCity and then commit the changes to the pom. This can certainly be triggered when Y
is built, you could even provide the version (it must be a list
or a range
):
您可以从 TeamCity 执行此命令,然后将更改提交到 pom。这当然可以在Y
构建时触发,您甚至可以提供版本(必须是 alist
或 a range
):
$ mvn versions:update-parent -DparentVersion=[1.0.0,1.0.1] //or [1.0.0,1.5.0)
Documentation
文档
See versions-maven-plugin's documentation, especially:
请参阅versions-maven-plugin的文档,尤其是:
versions:update-parent
版本:更新父
updates the parent section of a project so that it references the newest available version. For example, if you use a corporate root POM, this goal can be helpful if you need to ensure you are using the latest version of the corporate root POM.
更新项目的父部分,以便它引用最新的可用版本。例如,如果您使用公司根 POM,那么如果您需要确保使用最新版本的公司根 POM,此目标会很有帮助。
versions:set
版本:设置
can be used to set the project version from the command line.
可用于从命令行设置项目版本。
versions:commit
版本:提交
removes the pom.xml.versionsBackup
删除 pom.xml.versionsBackup
versions:update-child-modules
版本:更新子模块
updates the parent section of the child modules of a project so the version matches the version of the current project. For example, if you have an aggregator pom that is also the parent for the projects that it aggregates and the children and parent versions get out of sync, this mojo can help fix the versions of the child modules. (Note you may need to invoke Maven with the -N option in order to run this goal if your project is broken so badly that it cannot build because of the version mis-match).
更新项目子模块的父部分,使版本与当前项目的版本匹配。例如,如果您有一个聚合器 pom,它也是它聚合的项目的父级,并且子级和父级版本不同步,则此 mojo 可以帮助修复子模块的版本。(请注意,如果您的项目因版本不匹配而无法构建,您可能需要使用 -N 选项调用 Maven 以运行此目标)。