Java Jacoco聚合报告显示0%的覆盖率

Java Jacoco聚合报告显示0%的覆盖率,java,report,code-coverage,jacoco,jacoco-maven-plugin,Java,Report,Code Coverage,Jacoco,Jacoco Maven Plugin,我正在尝试为多模块项目的单元测试添加聚合覆盖率报告。覆盖率报告按预期为各个模块生成。但在报告模块目标中生成的聚合报告显示覆盖率为0% 模块的结构如下所示: Root | | - - - Components module | | - - - - - - - - - Sub module A | | - - - - - - - - - Sub module B | | - - - - -

我正在尝试为多模块项目的单元测试添加聚合覆盖率报告。覆盖率报告按预期为各个模块生成。但在报告模块目标中生成的聚合报告显示覆盖率为0%

模块的结构如下所示:

Root
|
|
- - - Components module
      |
      |
      - - - - - - - - - Sub module A
      |
      |
      - - - - - - - - - Sub module B
      |
      |
      - - - - - - - - - Aggregate report module
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.wso2.carbon.apimgt</groupId>
    <artifactId>apimgt</artifactId>
    <version>6.8.148-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>report</artifactId>
  <name>Aggregate Report</name>

  <properties>
    <code.coverage.project.folder>${basedir}/../</code.coverage.project.folder>
    <code.coverage.overall.data.folder>${basedir}/../target/aggregate.exec</code.coverage.overall.data.folder>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.rest.api.admin</artifactId>
      <type>war</type>
    </dependency>

    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.impl</artifactId>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.plugin.version}</version>
        <configuration>
          <!-- Jacoco prepare-agent builds some command-line params without -->
          <!-- which jacoco will not instrument. Hence it is important to add -->
          <!-- those command-line params here (${argLine} holds those params) -->
          <argLine>${argLine} -Xms256m -Xmx2048m</argLine>
          <forkCount>1</forkCount>
          <runOrder>random</runOrder>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>report-aggregate</id>
            <phase>verify</phase>
            <goals>
              <goal>report-aggregate</goal>
            </goals>
          </execution>
          <execution>
            <id>merge-results</id>
            <phase>verify</phase>
            <goals>
              <goal>merge</goal>
            </goals>
            <configuration>
              <fileSets>
                <fileSet>
                  <directory>${basedir}/../</directory>
                  <includes>
                    <include>**/target/jacoco.exec</include>
                  </includes>
                </fileSet>
              </fileSets>
              <destFile>${basedir}/../target/aggregate.exec</destFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
我遵循了这个示例项目:

现有根pom包含插件配置,如下所示,我没有更改任何内容:

<plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <executions>
                        <execution>
                            <id>default-instrument</id>
                            <goals>
                                <goal>instrument</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-restore-instrumented-classes</id>
                            <goals>
                                <goal>restore-instrumented-classes</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>pre-unit-test</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <append>true</append>
                                <destFile>${basedir}/target/coverage-reports/jacoco-ut.exec</destFile>
                            </configuration>
                        </execution>
                        <execution>
                            <id>pre-integration-test</id>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                            <configuration>
                                <destFile>${basedir}/target/coverage-reports/jacoco-it.exec</destFile>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-integration-test</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${basedir}/target/coverage-reports/jacoco-it.exec</dataFile>
                                <outputDirectory>${basedir}/target/coverage-reports/site/jacoco-it</outputDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-unit-test</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${basedir}/target/coverage-reports/jacoco-ut.exec</dataFile>
                                <outputDirectory>${basedir}/target/coverage-reports/site/jacoco-ut</outputDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>merge-results</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>merge</goal>
                            </goals>
                            <configuration>
                                <fileSets>
                                    <fileSet>
                                        <directory>${basedir}/target/coverage-reports</directory>
                                        <includes>
                                            <include>*.exec</include>
                                        </includes>
                                    </fileSet>
                                </fileSets>
                                <destFile>${basedir}/target/coverage-reports/aggregate.exec</destFile>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-merge-report</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${basedir}/target/coverage-reports/aggregate.exec</dataFile>
                                <outputDirectory>${basedir}/target/coverage-reports/site/jacoco-aggregate
                                </outputDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>default-check</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                            <configuration>
                                <dataFile>${basedir}/target/coverage-reports/aggregate.exec</dataFile>
                                <rules>
                                    <rule>
                                        <element>BUNDLE</element>
                                        <limits>
                                            <limit>
                                                <counter>INSTRUCTION</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>0.00</minimum>
                                            </limit>
                                        </limits>
                                    </rule>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven.surefire.plugin.version}</version>
                    <configuration>
                        <systemPropertyVariables>
                            <jacoco-agent.destfile>${basedir}/target/coverage-reports/jacoco-ut.exec
                            </jacoco-agent.destfile>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.22.2</version>
                    <configuration>
                        <systemPropertyVariables>
                            <jacoco-agent.destfile>${basedir}/target/coverage-reports/jacoco-it.exec
                            </jacoco-agent.destfile>
                        </systemPropertyVariables>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

org.jacoco
jacocomaven插件
${jacoco.version}
默认工具
仪器
默认还原检测类
恢复插入指令的类
单元前测试
配制剂
真的
${basedir}/target/coverage reports/jacoco-ut.exec
预集成测试
准备代理集成
${basedir}/target/coverage reports/jacoco-it.exec
整合后测试
整合后测试
报告
${basedir}/target/coverage reports/jacoco-it.exec
${basedir}/target/coverage reports/site/jacoco it
单元后测试
准备包装
报告
${basedir}/target/coverage reports/jacoco-ut.exec
${basedir}/target/coverage reports/site/jacoco ut
合并结果
验证
合并
${basedir}/target/coverage报告
*行政长官
${basedir}/target/coverage reports/aggregate.exec
合并后报告
验证
报告
${basedir}/target/coverage reports/aggregate.exec
${basedir}/target/coverage reports/site/jacoco aggregate
默认检查
检查
${basedir}/target/coverage reports/aggregate.exec
捆
指示
覆盖层
0
org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin.version}
${basedir}/target/coverage reports/jacoco-ut.exec
org.apache.maven.plugins
maven故障保护插件
2.22.2
${basedir}/target/coverage reports/jacoco-it.exec
集成测试
验证
添加的报表聚合模块pom I如下:

Root
|
|
- - - Components module
      |
      |
      - - - - - - - - - Sub module A
      |
      |
      - - - - - - - - - Sub module B
      |
      |
      - - - - - - - - - Aggregate report module
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.wso2.carbon.apimgt</groupId>
    <artifactId>apimgt</artifactId>
    <version>6.8.148-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>report</artifactId>
  <name>Aggregate Report</name>

  <properties>
    <code.coverage.project.folder>${basedir}/../</code.coverage.project.folder>
    <code.coverage.overall.data.folder>${basedir}/../target/aggregate.exec</code.coverage.overall.data.folder>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.rest.api.admin</artifactId>
      <type>war</type>
    </dependency>

    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.impl</artifactId>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.plugin.version}</version>
        <configuration>
          <!-- Jacoco prepare-agent builds some command-line params without -->
          <!-- which jacoco will not instrument. Hence it is important to add -->
          <!-- those command-line params here (${argLine} holds those params) -->
          <argLine>${argLine} -Xms256m -Xmx2048m</argLine>
          <forkCount>1</forkCount>
          <runOrder>random</runOrder>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>report-aggregate</id>
            <phase>verify</phase>
            <goals>
              <goal>report-aggregate</goal>
            </goals>
          </execution>
          <execution>
            <id>merge-results</id>
            <phase>verify</phase>
            <goals>
              <goal>merge</goal>
            </goals>
            <configuration>
              <fileSets>
                <fileSet>
                  <directory>${basedir}/../</directory>
                  <includes>
                    <include>**/target/jacoco.exec</include>
                  </includes>
                </fileSet>
              </fileSets>
              <destFile>${basedir}/../target/aggregate.exec</destFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

4.0.0
org.wso2.carbon.apimgt
阿皮姆特
6.8.148-快照
../pom.xml
报告
汇总报告
${basedir}//
${b