2016-01-24 54 views
3
<profile> 
     <id>integration-tests</id> 
     <activation> 
      <property> 
       <name>integrations</name> 
       <value>true</value> 
      </property> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>exec-maven-plugin</artifactId> 
        <version>1.4.0</version> 
        <executions> 
         <execution> 
          <id>script-chmod</id> 
          <phase>integration-test</phase> 
          <goals> 
           <goal>exec</goal> 
          </goals> 
          <configuration> 
           <executable>chmod</executable> 
           <arguments> 
            <argument>+x</argument> 
            <argument>integration-test-docker/integrations.sh</argument> 
           </arguments> 
          </configuration> 
         </execution> 
         <execution> 
          <id>script-exec</id> 
          <phase>integration-test</phase> 
          <goals> 
           <goal>exec</goal> 
          </goals> 
          <configuration> 
           <executable>integration-test-docker/integrations.sh</executable> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 

此配置文件中有更多的東西,但我只包括我想運行的東西。我怎樣才能執行這個特定的目標,這個特定的插件?運行一個配置文件中的插件的目標

我試圖mvn exec:exec,但我得到這個

[錯誤]未能執行目標 org.codehaus.mojo:上 項目EXEC(默認CLI):EXEC-Maven的插件:1.3.2安藤:參數 '可執行' 爲目標 org.codehaus.mojo:EXEC-行家-插件:1.3.2:EXEC缺失或無效 - > [幫助1]

此外,錯誤輸出指示版本1.3.2,但我正在使用1.4.0

回答

7

你調用的exec-maven-pluginexec目標,因爲它的配置(你的意思是一個)是profile默認情況下是不活躍的一部分,它不是由您的執行mvn exec:exec激活得到一個錯誤。

如果您嘗試激活通過其屬性激活配置文件(根據配置)或明確(通過-P選項),然後Maven會知道你提到的這Exec的Maven插件:

mvn exec:exec -Pintegration-tests 

mvn exec:exec -Dintegrations=true 

因此,配置文件將處於活動狀態,您的Exec Maven插件配置將成爲構建的一部分。

但是,您正在配置插件的兩次執行,並且沒有全局配置,因此它也會再次失敗。

沒有爲或縮小execution子部分的plugin部分configuration元件之間的difference:出來,它會被默認應用到所有執行和命令線處決;它將應用於應用的特定執行(覆蓋或與任何缺省合併,如果提供)。

如果你想同時運行處決,你就可以只啓動的情景:

mvn clean verify -Pintegration-tests 

mvn clean verify -Dintegrations=true 

然而,它將執行配置文件的全部內容加上整個構建直到指定的phase

如果你想在命令行中僅執行插件目標(exec),那麼你需要指定一個默認的配置(也只能)如下:

<profile> 
    <id>integration-tests</id> 
    <activation> 
     <property> 
      <name>integrations</name> 
      <value>true</value> 
     </property> 
    </activation> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.4.0</version> 
       <configuration> 
        <!-- here your default configuration --> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</profile> 

缺省設置將被應用到命令行執行。

或者,也可以覆蓋default execution iddefault-cli),其從所述命令行中使用由每個插件執行,以及可以看到作爲問題的提到的錯誤的一部分。因此,您可以爲該執行提供特定配置,而不是針對所有其他(如果有的話)執行(假定它們不提供它們自己的配置)。這裏有一個例子:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.4.0</version> 
    <executions> 
     <execution> 
      <id>default-cli</id> 
      <configuration> 
       <!-- here your specific command line execution --> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

如果要執行的命令行兩次執行,只有這些執行(因此,不能作爲一個Maven階段的一部分),您可以檢查該主題this answer(簡稱:它是可能的,因爲Maven 3.3.1,否則對早期版本提供建議)。

因此,執行將是如下:

mvn org.codehaus.mojo:exec-maven-plugin:1.4.0:[email protected] -Dintegrations=true 

注:

  • 我再次激活輪廓具有執行作爲構建
  • 這一次的一部分我沒有通過插件aliasexec和期望的目標exec,但它的完整Maven GAV(groupId,artifactId,版本)在通用Maven模式中依賴關係(:),所以我們得到org.codehaus.mojo:exec-maven-plugin:1.4.0,然後通過目標,所以我們得到額外的:exec,然後使用上面提到的新功能和新的@運算符我傳遞所需的執行ID(在POM中定義)。
相關問題