Java Maven 更新 POM 中的依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/973081/
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
Maven update dependencies in POM
提问by javamonkey79
Are there any preexisting Maven plugins or commands to update the dependencies in the POM? Example: (if this was in my POM)
是否有任何预先存在的 Maven 插件或命令来更新 POM 中的依赖项?示例:(如果这是在我的 POM 中)
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
Is there a command or plugin I can run to get it to update the dependency to:
是否有我可以运行的命令或插件来获取它以将依赖项更新为:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
采纳答案by Dominic Mitchell
Try the maven-versions-plugin, in particular, the versions:use-latest-versionsgoal.
回答by Robert Munteanu
No there is isn't. And be happy there is not. How would such a tool know how to upgrade your dependencies?
不,没有。并高兴的是没有。这样的工具如何知道如何升级您的依赖项?
With breakages possibly happening between minor versions, it would be a disaster waiting to happen.
由于次要版本之间可能发生损坏,这将是一场等待发生的灾难。
But you can always write your own Mojofor that.
但是您始终可以为此编写自己的 Mojo。
- get latest version of dependency from Maven repository
- compare with version from pom.xml
- rewrite pom.xml
- run
mvn test - ?
- Profit!
- 从 Maven 存储库获取最新版本的依赖项
- 与 pom.xml 中的版本进行比较
- 重写 pom.xml
- 跑
mvn test - ?
- 利润!
回答by rperez
you can use dependencyManagement in your parent pom:
你可以在你的父 pom 中使用 dependencyManagement:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</dependencyManagement>
this way, you need to change the version only once in the parent POM
这样,您只需在父 POM 中更改一次版本
回答by piepera
I prefer using mvn versions:display-dependency-updates; this generates a report of which dependencies can be upgraded, but lets you modify the POMs yourself. There's also a display-plugin-updatescommand for plugins.
我更喜欢使用mvn versions:display-dependency-updates;这会生成一份报告,说明哪些依赖项可以升级,但允许您自己修改 POM。还有一个用于插件的display-plugin-updates命令。
回答by Scott Izu
Personally, I think there should be an additional parameter in maven that would allow you to add to the pom.xml.
就个人而言,我认为 maven 中应该有一个额外的参数可以让你添加到 pom.xml 中。
请参阅http://maven.40175.n5.nabble.com/Is-there-any-maven-plugin-to-add-dependency-to-existing-pom-xml-td2839092.html#a5772853 上的帖子
Here, you can add the following to your pom.xml file:
在这里,您可以将以下内容添加到 pom.xml 文件中:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
...
</plugins>
...
</build>
...
</project>
...
...
Then backup your pom.xml file via version set command:
然后通过 version set 命令备份你的 pom.xml 文件:
mvn versions:set -DnewVersion=9.9.9
Run latest versions:
运行最新版本:
mvn versions:use-latest-versions
and diff the pom.xml files, pom.xml and pom.xml.versionsBackup
并区分 pom.xml 文件,pom.xml 和 pom.xml.versionsBackup

