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