问题描述
我有一个带有插件的 Maven pom.xml,我希望能够在命令行上进行控制.一切正常,除非在网上搜索了一段时间后我不知道如何为我的控件属性设置默认值:
I have a Maven pom.xml with a plugin that I want to be able to control on the command line. Everything works otherwise fine, except even after searching the net a while I can't figure out how to set a default value for my control property:
<plugin>
...
<configuration>
<param>${myProperty}</param>
</configuration>
...
</plugin>
所以如果我用
mvn -DmyProperty=something ...
一切都很好,但我想在没有 -DmyProperty=...
开关的情况下也为 myProperty 分配一个特定的值.这怎么办?
everything's fine, but I'd like to have a specific value assigned to myProperty also without the -DmyProperty=...
switch. How can this be done?
推荐答案
您可以在 /
或如下所示的配置文件中定义属性默认值.当您在命令行上使用 -DmyProperty=anotherValue
提供属性值时,它将覆盖 POM 中的定义.也就是说,POM 中属性值的所有定义仅设置为属性的默认值.
You can have the property default value defined in <build>/<properties>
or in a profile like shown below. When you supply the property value on command line with -DmyProperty=anotherValue
then it will override the definition from the POM. That is, all definitions of property values in the POM are set only a default value for the properties.
<profile>
...
<properties>
<myProperty>defaultValue</myProperty>
</properties>
...
<configuration>
<param>${myProperty}</param>
</configuration>
...
</profile>
这篇关于为自定义 Maven 2 属性设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!