如何合并 2 个 jacoco 覆盖率报告(.exec 文件),无论 Maven 生命周期如何

use*_*223 5 merge code-coverage maven jacoco jacoco-maven-plugin

我的 pom 中有一个 jacoco 插件来获取 junit 测试覆盖率,并且我正在从不同的服务器转储另一个报告。如何合并这 2 个 jacoco 覆盖率报告(.exec 文件),无论 Maven 生命周期如何。

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.6.201602180812</version>
    <executions>
      <execution>
        <goals>
          <goal>prepare-agent</goal>
        </goals>
        <configuration>
          <destFile>${project.build.directory}</destFile>
        </configuration>     
      </execution>
    </executions>        
</plugin>
Run Code Online (Sandbox Code Playgroud)

spi*_*spi 1

您可以使用目标“合并”,将其与您选择的阶段绑定:http://www.eclemma.org/jacoco/trunk/doc/merge-mojo.html

也许有这样的配置:

<plugin>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        ...
        <execution>
            <id>merge-all-jacoco</id>
            <goals><goal>merge</goal></goals>
            <phase>install</phase>
            <configuration> 
              <destFile>merged.exec</destFile> 
              <fileSets>
                <fileSet>
                  <directory>${project.build.directory}</directory>
                  <includes>
                    <include>*.exec</include>
                  </includes>
                </fileSet>
              </fileSets>
            </configuration> 
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)