2012-02-16 14 views
0

如果設置了系統屬性,我想運行'exec-maven-plugin'。我如何在Maven 3.x中完成此任務?如果在Maven 3.x中設置系統屬性ID,如何運行exec-maven-plugin?

例如,給定:

mvn clean install -DrunTheExec="yes" 

那我該怎麼實現這個邏輯:

<!-- if $(runTheExec) == yes then run this plugin --> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      ... 
     </plugin> 

回答

1

我正要加入同樣的建議的喬納森,但使用配置文件的方式有點不同。

<profiles> 
    <profile> 
    <id>runTheExec</id> 
    <activation> 
     <activeByDefault>false</activeByDefault> 
    </activation> 
    <build> 
     <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
    ... 

然後將其激活:

mvn clean install -PrunTheExec 
+0

兩者都是很好的答案,但我會要挑這一個作爲答案,因爲默認選項是一個很好的補充。我會投兩個答案。 – TERACytE 2012-02-17 00:04:50

3

你需要在你的POM中定義一個輪廓,它裏面所定義的插件。在你的榜樣,這將是:

<profiles> 
    <profile> 
    <activation> 
     <property> 
     <name>runTheExec</name> 
     <value>yes</value> 
     </property> 
    </activation> 
    <plugins> 
     <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     ... 
     </plugin> 
    </plugins> 
    </profile> 
</profiles> 
相關問題