由于 maven-compiler-plugin v2.0.2 中的一个错误(在 v2.3.2 版本中修复),我损失了 2 个小时的时间。
显然,如果您不指定 Maven 编译器插件的版本,Maven 2.2.1 只会为您提供 v2.0.2。
我们的项目使用 15 个以上的 Maven 插件。其中一些我们希望确定某个版本,但大多数(如编译器插件)我们希望无需考虑即可升级。
有没有一种方法可以使用 Maven 自动执行此操作,或者我们是否必须指派某人执行每月研究可能的 Maven 插件升级,然后更改父 POM 中的 PluginManagement 版本号的吃力不讨好的任务?
I just lost 2 hours of time because of a bug in the maven-compiler-plugin v2.0.2 that was fixed in version v2.3.2.
Apparently if you don't specify the version of the Maven compiler plugin, Maven 2.2.1 just gives you v2.0.2.
Our project uses 15+ Maven plugins. Some of them we want to pin down a certain version, but most of which (like the compiler plugin) we'd like to upgrade without having to think about it.
Is there a way to do this automatically with Maven, or do we have to assign someone the thankless task of researching possible Maven plug-in upgrades every month and then changing the PluginManagement version numbers in our parent POM?
发布评论
评论(4)
是的,从 Maven 2.0.9 开始(请参阅MNG-3395) 核心和常用插件的版本固定在 super POM 和 Maven 出于构建重现性的目的禁用了插件版本发现。
正如上面所暗示的,这是一个坏主意。您只是不希望 Maven 构建由于某些插件更新而突然开始失败。换句话说,您应该使用固定版本,而不这样做是一种不好的做法。实际上,Maven 3.0 提倡这种做法,并在您不这样做时发出警告。在 3.1 中,您必须指定版本(请参阅 MNG- 1968 年)。
就我个人而言,我使用 Maven Enforcer 插件 及其 需要插件版本 规则来强制执行此实践(这意味着如果您不这样做,构建将会失败) t 锁定插件版本)。
正如所建议的, 版本 Maven 插件 的目标是允许检查是否有更新的版本插件、依赖项等的版本(请注意,
-cpu
在 Maven 3.0 中已弃用,并将从未来版本中删除)。但真正的问题是:为什么你总是想使用终极版本? IMO,没有充分的理由这样做,只有在需要修复某些内容时才应该升级(“如果它没有损坏,就不要修复它”)。
底线:使用固定的插件版本并忘记自动更新、版本范围等。
Yes, as of Maven 2.0.9 (see MNG-3395) the versions of core and common plugins are fixed in the super POM and Maven disabled plugin version discovery for the sake of build reproducibility.
As hinted above, this is a bad idea. You simply don't want a maven build to suddenly start to fail because of some plugin update. In other words, you should use fixed versions and not doing so is a bad practice. Actually, Maven 3.0 promotes this practice and warns you if you don't do so. And in 3.1, you will have to specify a version (see MNG-1968).
Personally, I use the Maven Enforcer Plugin and its Require Plugin Versions rule to enforce this practice (which means the build will fail if you don't lock down plugins versions).
As suggested, the Versions Maven Plugin has goals allowing to check if there are more recent versions of plugins, dependencies, etc (and note that
-cpu
is deprecated in Maven 3.0 and will be removed from future versions).But the real question is: why do you want to always use ultimate versions? IMO, there is no good reason to do so, you should upgrade only if there is something to fix ("if it ain't broke, don't fix it").
Bottom line: use fixed plugins versions and forget automatic updates, version ranges, etc.
您可以将 versions-maven-plugin 之类的东西绑定到您的主要构建中,这样您就可以得到每个版本的报告显示您的插件是否是最新的。
有关详细信息,请参阅此链接:显示插件更新
如果您想变得更奇特,可以让 CI 服务器通过脚本运行 Maven 构建的输出,以检查表示新版本的
[WARNING]
日志条目,然后让它通知您的相关成员团队通过电子邮件或其他通知。You could tie something like the versions-maven-plugin to your primary build such that you get a report on each build that shows whether your plugins are up to date.
See this link for detail on how: Display Plugin Updates
If you want to get fancy, have your CI server run the output of your maven build through a script to check for
[WARNING]
log entries that signal new versions and then have it notify relevant members of your team via email or some other notification.今天我第二次写这篇文章:
尝试使用
-cpu
标志。mvn -help
的输出:The second time I get to write this today:
Try using the
-cpu
flag. Output frommvn -help
:您还可以在插件中使用版本范围。
You could also use version ranges in your plugins.