java 从命令行覆盖 pom pluginManagement 中定义的 Maven 插件配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4660047/
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
Override Maven plugin configuration defined in the pom pluginManagement from the command line
提问by rustyx
The POM that my project inherits contains some <pluginManagement>
for the release
plugin that specifies some additional arguments
.
我的项目继承的 POM 包含一些<pluginManagement>
用于release
指定一些额外arguments
.
My question is:Is there a way to override the arguments
parameter from the command line in this case?
我的问题是:arguments
在这种情况下,有没有办法从命令行覆盖参数?
The parent POM has this:
父 POM 有这个:
<pluginManagement>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<arguments>-Prelease</arguments>
</configuration>
</plugin>
</pluginManagement>
Due to that the command line argument doesn't work:
由于命令行参数不起作用:
mvn release:prepare -Darguments="-Pmock -Prelease"
The -Darguments="-Pmock -Prelease"
part has no effect. When arguments
is not already specified, it works.
该-Darguments="-Pmock -Prelease"
部分没有影响。当arguments
尚未指定时,它可以工作。
It is not possible for me to modify the parent POM or not to use it.
我无法修改父 POM 或不使用它。
采纳答案by rustyx
Found the solution. In myPOM I add this which overrides the settings in the parentPOM and allows to specify additional arguments on command line, e.g. -Darguments=-Pmock
找到了解决办法。在我的POM 中,我添加了它覆盖父POM 中的设置并允许在命令行上指定其他参数,例如-Darguments=-Pmock
<pluginManagement>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<arguments>${arguments} -Prelease</arguments>
</configuration>
</plugin>
</pluginManagement>
回答by Stefan Birkner
You cannot override a configuration, which is already set in the POM (see Maven Bug MNG-4979). You may use variables in order to avoid this behaviour. The snippet of your answer makes use of it.
您不能覆盖已在 POM 中设置的配置(请参阅Maven Bug MNG-4979)。您可以使用变量来避免这种行为。您的答案片段使用了它。