2015-04-02 57 views
2

請考慮jacoco例子(http://www.eclemma.org/jacoco/trunk/doc/examples/build/pom-it.xml爲什麼列出插件的目標而不綁定到階段?

<plugins> 
    <plugin> 
     <groupId>org.jacoco</groupId> 
     <artifactId>jacoco-maven-plugin</artifactId> 
     <version>0.7.5-SNAPSHOT</version> 
     <executions> 
      <execution> 
       <id>default-prepare-agent</id> 
       <goals> 
        <goal>prepare-agent</goal> 
       </goals> 
      </execution> 
      <execution> 
       <id>default-prepare-agent-integration</id> 
       <goals> 
        <goal>prepare-agent-integration</goal> 
       </goals> 
      </execution> 
      <execution> 
       <id>default-report</id> 
       <goals> 
        <goal>report</goal> 
       </goals> 
      </execution> 
      <execution> 
       <id>default-report-integration</id> 
       <goals> 
        <goal>report-integration</goal> 
       </goals> 
      </execution> 
      <execution> 
       <id>default-check</id> 
       <goals> 
        <goal>check</goal> 
       </goals> 
       <configuration> 
        <rules> 
         <!-- implmentation is needed only for Maven 2 --> 
         <rule implementation="org.jacoco.maven.RuleConfiguration"> 
          <element>BUNDLE</element> 
          <limits> 
           <!-- implmentation is needed only for Maven 2 --> 
           <limit implementation="org.jacoco.report.check.Limit"> 
            <counter>COMPLEXITY</counter> 
            <value>COVEREDRATIO</value> 
            <minimum>0.60</minimum> 
           </limit> 
          </limits> 
         </rule> 
        </rules> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.16</version> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-failsafe-plugin</artifactId> 
     <version>2.16</version> 
     <executions> 
      <execution> 
       <id>default-integration-test</id> 
       <goals> 
        <goal>integration-test</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 
</plugins> 

現在我知道了,你可以在插件的目標綁定到一個Maven階段採取這一POM摘錄,當Maven執行一個特定的階段,其運行的目標。

剛剛列出maven故障安全插件的集成測試目標而沒有將其綁定到某個東西的目的是什麼?

與jacoco報告和其他目標相同嗎?我不認爲你可以強制插件只執行那些列出的目標嗎?

非常感謝

回答

3

問題是,一個插件可以定義默認的生命週期階段,在這個階段,合適的目標被綁定(許多插件都這樣做)。在這種情況下,您不需要明確指定pom文件中的生命週期階段。

例如maven-failsafe-plugin的目標是integration-test。該目標與integration-test生命週期階段具有默認綁定。這裏從文檔的摘錄:

說明:

使用神火運行集成測試。屬性:

  • 要求執行Maven項目。
  • 要求對作用域進行依賴關係解析:測試。
  • 目標是線程安全的並支持並行構建。
  • 默認綁定到生命週期階段:集成測試。

這就是爲什麼你不需要給生活cylce階段在這樣的結構的原因:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <version>2.18.1</version> 
    <executions> 
     <execution> 
      <id>default-integration-test</id> 
      <goals> 
       <goal>integration-test</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

同樣意味着對jacoco Maven插件。

-1

如果我理解正確,M2E將工作區完全或增量構建過程中執行的插件目標。

下面的文章可以提供一些線索:

http://eclipse.org/m2e/documentation/m2e-execution-not-covered.html

你是正確的,在命令行中,您將無法指定目標,因爲它是一個插件目標,而不是依賴於一個階段。這可能是專門用於M2E集成的一個古怪的用法。

+0

這個問題既沒有標記_Eclipse_也沒有_m2e_。 – 2015-06-20 13:55:11

相關問題