覆盖Maven插件参数 [英] Override Maven Plugin Parameters
问题描述
我有一个Maven插件,它在POM文件中配置为
I have a Maven plugin and it is configured in the POM file as
<build>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>example-maven-plugin</artifactId>
<configuration>
<scriptsPath>scripts</scriptsPath>
</configuration>
</plugin>
</plugins>
</build>
现在,我想从命令行覆盖scriptsPath
,以便运行
Now I want to override that scriptsPath
from from command line so I run
mvn -X example-maven-plugin:goal -DscriptsPath=scripts1
我可以看到scriptsPath
的值仍然是scripts
而不是scripts1
.可以从命令行覆盖配置参数吗?
I can see that value of the scriptsPath
is still scripts
and not scripts1
. Could the configuration parameter be overriden from the command line ?
推荐答案
不幸的是,没有通用的方法可以通过使用属性来覆盖maven插件配置.如果插件文档未明确允许您使用属性来设置配置值,则可以使用以下模式:
Unfortunately, there is no general way to override maven plugin configuration by using properties. If the plugin documentation does not explicitly allow you to use a property to set the configuration value you can use following pattern:
<properties>
<scripts.path>scripts</scripts.path>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>example-maven-plugin</artifactId>
<configuration>
<scriptsPath>${scripts.path}</scriptsPath>
</configuration>
</plugin>
</plugins>
</build>
然后以
的身份执行Maven
and then execute maven as
mvn -X example-maven-plugin:goal -Dscripts.path=scripts1
这篇关于覆盖Maven插件参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!