为自定义Maven 2属性设置默认值 [英] Setting default values for custom Maven 2 properties

查看:220
本文介绍了为自定义Maven 2属性设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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>

所以,如果我运行Maven与

So if I run Maven with

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?

推荐答案

您可以在<build>/<properties>或如下所示的配置文件中定义属性默认值.当在命令行中为属性值提供-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属性设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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