【Maven】mvn -D 和 -p参数

2019-10-10  本文已影响0人  Mr丶Anderson

-D代表(Properties属性)

使用命令行设置属性-D的正确方法是:

    <!--自定义变量 -->
    <properties>
        <xml>testng</xml>
    </properties>
    ......
    ......
     <suiteXmlFiles>
            <suiteXmlFile>src/test/java/xxx/${xml}.xml</suiteXmlFile>
     </suiteXmlFiles>
mvn clean test -U -Dxml=testng-test1

命令行 mvn -D propertyName=propertyValue clean package:

以上参考:http://stackoverflow.com/questions/17332857/how-to-use-the-mvn-d-to-set-multiple-properties-in-maven-via-command-line

-P代表(Profiles配置文件)

也就是说在<profiles>指定的<id>中,可以通过-P进行传递或者赋值。

  <profiles>
      <profile>
          <id>test</id>
          ...
      </profile>
   </profiles>
<profile>
   <id>test</id>
   <activation>
      <property>
         <name>env</name>
         <value>test</value>
      </property>
   </activation>
   ...
</profile>

具体实践例子,参考:http://www.cnblogs.com/EasonJim/p/6828743.html

总结

更多的参考Maven帮助文档:
http://stackoverflow.com/questions/17332857/how-to-use-the-mvn-d-to-set-multiple-properties-in-maven-via-command-line
http://books.sonatype.com/mvnref-book/reference/running-sect-options.html#running-sect-define-prop
Google搜索关键字:maven d flag

上一篇 下一篇

猜你喜欢

热点阅读