2017-09-13 225 views
0

我的項目包含以下結構多模塊項目Jacoco Maven的配置時,一些模塊存在於子目錄

pom.xml 
| 
| 
-----sub module A pom.xml 
| 
| 
-----sub module B pom.xml 
| 
| 
-----sub module plugins/C pom.xml 
| 
| 
-----sub module plugins/D pom.xml 

我已經配置了這樣的

<modules> 
    <module>A</module> 
    <module>B</module> 
    <module>plugins/C</module> 
    <module>plugins/D</module> 
</modules> 
<plugin> 
    <groupId>org.jacoco</groupId> 
    <artifactId>jacoco-maven-plugin</artifactId> 
    <version>0.7.7.201606060606</version> 
    <executions> 
     <execution> 
      <goals> 
       <goal>prepare-agent</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>report</id> 
      <phase>prepare-package</phase> 
      <goals> 
       <goal>report</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

主要POM當我運行「MVN驗證「jacoco報告只生成模塊A & B.對於模塊插件/ C和插件/ D Jacoco沒有執行,因此沒有報告。

回答

0

這個問題不是關於jacoco-maven-plugin,而是關於aggregationinheritance在Maven中。

鑑於example/pom.xml

<project> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>org.example</groupId> 
    <artifactId>example</artifactId> 
    <version>0.1-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <modules> 
    <module>A</module> 
    <module>plugins/C</module> 
    </modules> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.jacoco</groupId> 
     <artifactId>jacoco-maven-plugin</artifactId> 
     <version>0.7.7.201606060606</version> 
     <executions> 
      <execution> 
      <goals> 
       <goal>prepare-agent</goal> 
      </goals> 
      </execution> 
      <execution> 
      <id>report</id> 
      <phase>prepare-package</phase> 
      <goals> 
       <goal>report</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

指定example/Aexample/plugins/C應建爲example構建的一部分,但不指定有關插件,性能配置的繼承什麼,等

對於繼承example/plugins/C/pom.xmlexample/pom.xml,第一個應聲明第二個爲parent

<project> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
    <groupId>org.example</groupId> 
    <artifactId>example</artifactId> 
    <version>0.1-SNAPSHOT</version> 
    <relativePath>../..</relativePath> 
    </parent> 

    <groupId>org.example</groupId> 
    <artifactId>C</artifactId> 
    <version>0.1-SNAPSHOT</version> 
</project> 

在插件的這樣的情況下的配置將被繼承和它們將被執行:

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T21:39:06+02:00) 
... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building C 0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (default) @ C --- 
... 

P.S.截至今天JaCoCo的版本是0.7.9。

0

爲您的plugins文件夾添加另一個pom.xml,讓它從您的父pom繼承,並將C & D定義爲子模塊,並從父pom中刪除模塊並添加plugins文件夾。並且不要忘記將父POM從C & D更改爲插件pom,應該這樣做。