如何在Maven POM中更新属性? [英] How can I update a property in a Maven POM?

查看:562
本文介绍了如何在Maven POM中更新属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个顶级Maven项目backendfrontend,它们按照自己的进度推进版本.由于每个模块都有多个模块,因此我在父/聚合POM的dependencyManagement部分中定义依赖项版本,并使用属性作为版本号.

I have two top-level Maven projects, backend and frontend, that advance versions at their own individual pace. Since each has multiple modules, I define my dependency versions in dependencyManagement sections in the parent/aggregate POMs and use a property for the version number.

我想用frontend上的版本号干净地更新属性,最好是任意更新,但是我可以接受要求实时上游版本匹配的情况.我尝试使用 versions:update-property ,但是目标似乎完全不起作用;不管实际上是否有匹配的上游版本,我都会得到以下调试输出:

I want to cleanly update the property with the version number on frontend, preferably arbitrarily, but I can live with requiring a live upstream version to match. I've tried using versions:update-property, but that goal seems to be completely non-functional; regardless of whether there's actually a matching upstream version, I get this debug output:

$ mvn versions:update-property -Dproperty=frontend.version -DnewVersion=0.13.2  -DautoLinkItems=false -X
...
[DEBUG] Searching for properties associated with builders
[DEBUG] Property ${frontend.version}
[DEBUG] Property ${frontend.version}: Looks like this property is not associated with any dependency...
[DEBUG] Property ${frontend.version}: Set of valid available versions is [0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.13.2, 0.13.3]
[DEBUG] Property ${frontend.version}: Restricting results to 0.13.2
[DEBUG] Property ${frontend.version}: Current winner is: null
[DEBUG] Property ${frontend.version}: Searching reactor for a valid version...
[DEBUG] Property ${frontend.version}: Set of valid available versions from the reactor is []
[INFO] Property ${frontend.version}: Leaving unchanged as 0.13.1
[INFO] ------------------------------------------------------------------------

我指定了-DautoLinkItems=false,这似乎没有效果; versions-maven-plugin仍会扫描我的所有POM以查找匹配的依赖项,举起手,然后退出.我也尝试在插件配置中将该属性的searchReactor设置为false.看来,插件(1)甚至在我明确地说要忽略依赖项时也会错误地扫描依赖项,并且(2)甚至过滤出明确的特定匹配项.

I've specified -DautoLinkItems=false, and this appears to have no effect; versions-maven-plugin still scans all of my POMs for matching dependencies, throws up its hands, and quits. I've also tried setting searchReactor to false for that property in the plugin configuration. It appears that the plugin (1) incorrectly scans the dependencies even when I've explicitly said to ignore them and (2) even filters out an explicit specific match.

是否有一种简单的方法可以将Maven属性条目重写为特定值,或者强制versions-maven-plugin执行我所说的操作而不验证版本号,或者使用另一个目标?我宁愿避免使用像sed这样的不懂XML的工具(就像我在类似问题中所建议的那样),但是我可以通过简单的XPath操作就可以了.

Is there a simple way to rewrite a Maven property entry to a specific value, either forcing versions-maven-plugin to do what I say without validating for a version number or by using another goal? I'd prefer to avoid a tool like sed that doesn't understand XML (as I've seen recommended in a similar question), but I would be okay with a simple XPath manipulation.

推荐答案

是否有一种简单的方法可以将Maven属性条目重写为特定值

Is there a simple way to rewrite a Maven property entry to a specific value

从版本2.5开始,我们可以使用set-property(文档):

Since version 2.5 we can use set-property (documentation):

mvn versions:set-property -Dproperty=your.property -DnewVersion=arbitrary_value

如前所述,set-property目标不会对您指定的值执行任何健全性检查",因此它应始终有效,但应谨慎使用.

As documented, the set-property goal does not perform any 'sanity checks' on the value you specify, so it should always work, but you should use with care.

这篇关于如何在Maven POM中更新属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆