Maven 命令参数-D和-P


Maven 命令参数-D和-P的区别

Maven 命令参数 中的 -D 表示 Properties属性,而 -P 表示 Profiles配置文件。

mvn -DpropertyName=propertyValue clean package

如果 propertyName 不存在于 pom.xml 文件中,它将被设置。如果 propertyName 已经存在 pom.xml 文件中,其值将被作为参数传递的值覆盖。要设置多个变量,请使用多个空格分隔符加-D:

mvn -DpropA=valueA -DpropB=valueB -DpropC=valueC clean package

例如,现有 pom.xml 文件如下所示:

<properties>
    <theme>myDefaultTheme</theme>
</properties>

那么在执行过程中 mvn -Dtheme=newValue clean package 会覆盖 theme 的值,具有如下效果:

<properties>
    <theme>newValue</theme>
</properties>

-P 代表 Profiles 配置文件的属性,也就是说在 <profiles> 指定的 <id> 中,可以通过-P进行传递或者赋值。

例如,现有 pom.xml 文件如下所示:

<profiles>
      <profile>
          <id>test</id>
          ...
      </profile>
</profiles>

执行 mvn test -Ptest 为触发配置文件。或者如下所示:

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

执行mvn test -Penv=test 为触发配置文件。

参考:

http://mvnbook.com/maven-properties.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM