Java 如何升级 Maven 插件的版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/786552/
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
How do I upgrade the version of a maven plugin?
提问by johnstok
I am using the maven-ear-plugin version 2.3.1 - I know there is a new version available: http://maven.apache.org/plugins/maven-ear-plugin/
我正在使用 maven-ear-plugin 版本 2.3.1 - 我知道有一个新版本可用:http: //maven.apache.org/plugins/maven-ear-plugin/
I can't work out how to upgrade to the latest version?
我不知道如何升级到最新版本?
采纳答案by andri
The default plugin versions are inherited from the Super POM, and you can check them with mvn help:effective-pom
.
默认插件版本继承自 Super POM,您可以使用mvn help:effective-pom
.
If you want to override the version provided there, add this to your POM:
如果您想覆盖那里提供的版本,请将其添加到您的 POM 中:
<project>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.1</version>
</plugin>
</plugins>
</build>
</project>
Replace the version with what you need.
用您需要的版本替换版本。
回答by MetroidFan2002
Some maven plugins are restricted to maven versions. For example, generally projects around here use Maven 2.0.4, which is restricted to use the war plugin 2.0.2 - this works with overlays. The 2.1-alpha whatever, however, that Maven 2.0.9 uses, does not - so we had to manually downgrade. Maven, unless otherwise instructed, will attempt to use the latest version of a plugin that it can according to its version.
一些 maven 插件仅限于 maven 版本。例如,这里的项目通常使用 Maven 2.0.4,它仅限于使用 war 插件 2.0.2 - 这适用于覆盖。然而,Maven 2.0.9 使用的 2.1-alpha 没有 - 所以我们不得不手动降级。除非另有指示,Maven 将尝试使用插件的最新版本,它可以根据其版本使用。
回答by Brian Fox
How the version of a plugin is selected, along with discussion about the plugin versions in the superpom is covered in detail here.
如何选择插件的版本,以及关于 superpom 中插件版本的讨论在这里详细介绍。
Actually the currently selected answer isn't quite right. It should be
实际上,当前选择的答案并不完全正确。它应该是
<project>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I explained why here:
我在这里解释了原因:
"The regular plugins section also allows the version and default configuration to be defined, and this is where the confusion lies. It is technically valid to define the plugin version and default configuration here, but I find it easier to grok the pom when following this guideline:
“常规插件部分还允许定义版本和默认配置,这就是混淆所在。在此处定义插件版本和默认配置在技术上是有效的,但我发现按照此操作时更容易理解 pom指南:
If the plugin block is not defining an execution (and thus binding maven to do something in the lifecycle), put that block in pluginManagment"
如果插件块没有定义执行(因此绑定 maven 在生命周期中做某事),将该块放在 pluginManagment 中”
回答by Pat
Even though this has already gotten the "approved answer", it turns out that there is this AWESOME versions pluginthat handles the neverending version maintenance problem.
尽管这已经得到了“批准的答案”,但事实证明有这个AWESOME versions 插件可以处理永无止境的版本维护问题。
For those lazy people here are some of its goals:
对于那些懒惰的人,这里有一些目标:
- versions:display-dependency-updatesscans a project's dependencies and produces a report of those dependencies which have newer versions available.
- versions:display-plugin-updatesscans a project's plugins and produces a report of those plugins which have newer versions available.
- versions:display-property-updatesscans a projectand produces a report of those properties which are used to control artifact versions and which properies have newer versions available.
- versions:update-parentupdates 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.
- versions:update-propertiesupdates properties defined in a project so that they correspond to the latest available version of specific dependencies. This can be useful if a suite of dependencies must all be locked to one version.
- versions:update-child-modulesupdates 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).
- versions:lock-snapshotssearches the pom for all -SNAPSHOT versions and replaces them with the current timestamp version of that -SNAPSHOT, e.g. -20090327.172306-4
- versions:unlock-snapshotssearches the pom for all timestamp locked snapshot versions and replaces them with -SNAPSHOT.
- versions:setcan be used to set the project version from the command line.
- versions:use-releasessearches the pom for all -SNAPSHOT versions which have been released and replaces them with the corresponding release version.
- versions:use-next-releasessearches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the next release version.
- versions:use-latest-releasessearches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the latest release version.
- versions:use-next-snapshotssearches the pom for all non-SNAPSHOT versions which have been a newer -SNAPSHOT version and replaces them with the next -SNAPSHOT version.
- versions:use-latest-snapshotssearches the pom for all non-SNAPSHOT versions which have been a newer -SNAPSHOT version and replaces them with the latest -SNAPSHOT version.
- versions:use-next-versionssearches the pom for all versions which have been a newer version and replaces them with the next version.
- versions:use-latest-versionssearches the pom for all versions which have been a newer version and replaces them with the latest version.
- version:display-dependency-updates扫描项目的依赖项并生成具有可用更新版本的依赖项的报告。
- 版本:display-plugin-updates扫描一个项目的插件,并生成一份关于那些有更新版本可用的插件的报告。
- 版本:display-property-updates扫描一个项目并生成一份关于那些用于控制工件版本的属性以及哪些属性有更新版本可用的报告。
- 版本:更新父更新项目的父部分,以便它引用最新的可用版本。例如,如果您使用公司根 POM,如果您需要确保使用最新版本的公司根 POM,则此目标会很有帮助。
- version:update-properties更新项目中定义的属性,以便它们对应于特定依赖项的最新可用版本。如果必须将一组依赖项全部锁定到一个版本,这会很有用。
- version:update-child-modules更新项目子模块的父部分,使版本与当前项目的版本匹配。例如,如果您有一个聚合器 pom,它也是它聚合的项目的父级,并且子级和父级版本不同步,则此 mojo 可以帮助修复子模块的版本。(请注意,如果您的项目因版本不匹配而无法构建,您可能需要使用 -N 选项调用 Maven 以运行此目标)。
- 版本:lock-snapshots在 pom 中搜索所有 -SNAPSHOT 版本,并用该 -SNAPSHOT 的当前时间戳版本替换它们,例如 -20090327.172306-4
- version:unlock-snapshots在 pom 中搜索所有时间戳锁定的快照版本,并用 -SNAPSHOT 替换它们。
- versions:set可用于从命令行设置项目版本。
- versions:use-releases在 pom 中搜索所有已发布的 -SNAPSHOT 版本,并将它们替换为相应的发布版本。
- 版本:use-next-releases在 pom 中搜索所有非 SNAPSHOT 版本的较新版本,并将它们替换为下一个版本。
- 版本:use-latest-releases在 pom 中搜索所有非 SNAPSHOT 版本的较新版本,并将它们替换为最新版本。
- 版本:use-next-snapshots在 pom 中搜索所有非 SNAPSHOT 版本,这些版本是较新的 -SNAPSHOT 版本,并将它们替换为下一个 -SNAPSHOT 版本。
- 版本:use-latest-snapshots在 pom 中搜索所有非 SNAPSHOT 版本,这些版本是较新的 -SNAPSHOT 版本,并将它们替换为最新的 -SNAPSHOT 版本。
- 版本:use-next-versions在 pom 中搜索所有较新版本的版本,并将它们替换为下一个版本。
- 版本:use-latest-versions在 pom 中搜索所有较新版本的版本,并将它们替换为最新版本。