报告和合并多模块 jacoco 报告与报告聚合

尝试获取一个显示来自多个模块的所有结果的 jacoco 报告。

我能够看到每个子模块在构建项目后都有一个,但不确定如何让它输出一个报告,该报告将合并每个模块的所有结果。jacoco.exec

这就是我包含在我的根中的内容:pom.xml

<plugin>
    <groupId>@project.groupId@</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>@project.version@</version>
</plugin>



<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我明确地创建了一个新模块用于报告目的。(例如,报告-聚合-模块)

在此示例中删除了组 ID 并使用通用工件 ID:

这就是我为这个报告聚合子模块添加的内容:pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>report-aggregate</artifactId>
        <groupId>com.name.group</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>


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

    <properties>
        <wildfly.version>10.0.0.Final</wildfly.version>
        <wildfly.artifactId>wildfly-dist</wildfly.artifactId>
    </properties>

    <dependencies>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module1</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module2</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module3</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId></groupId>
            <artifactId>sub-module4</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <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>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

一切似乎编译正常,jacoco exec似乎没有为报表聚合模块创建。有人知道这个问题的解决方案,或者如果我做错了吗?


答案 1

很抱歉,如果这是一个迟到的答案。

我假设你的根 pom.xml 是一个聚合器,由 、 和 组成。这是你麻烦的原因:由于你的根 pom.xml 是一个聚合器,它会在你的子模块之前运行 JaCoCo,所以你的最终报告是空的。您应该:<modules>module1module2report-aggregate

  • 将目标的配置从根POM移动到POM。这应该可以解决问题,因为您的POM使用,而不是。report-aggregatejacoco-maven-pluginreport-aggregatereport-aggregate<dependencies><modules>
  • 在根POM中保留目标的配置。prepare-agentjacoco-maven-plugin

我建议你看看jaCoCo论坛 https://groups.google.com/forum/#!topic/jacoco/FpdLbxsXSTY。它指的是一个完整的演示集成测试 https://github.com/jacoco/jacoco/tree/master/jacoco-maven-plugin.test/it/it-report-aggregate


答案 2

推荐