【问题标题】:Reporting and Merging multi-module jacoco reports with report-aggregate使用报告聚合报告和合并多模块 jacoco 报告
【发布时间】:2018-11-21 05:12:50
【问题描述】:

尝试获取一份 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 似乎没有为报告聚合模块创建。任何人都知道这个问题的解决方案,或者我是否做错了?

【问题讨论】:

  • report-aggregate-module 的 artifactId 是什么?它看起来和父级一样,编译起来很奇怪。您应该提供构建输出控制台的相关部分。

标签: java code-coverage jacoco qa jacoco-maven-plugin


【解决方案1】:

抱歉,如果这个答案来晚了。

我假设你的根 pom.xml 是一个聚合器,&lt;modules&gt;module1module2report-aggregate 组成。这是你的麻烦的原因:因为你的根 pom.xml 是一个聚合器,它在你的子模块之前运行 JaCoCo,所以你的最终报告是空的。你应该:

  • jacoco-maven-plugin的目标report-aggregate的配置从根POM移动到report-aggregate POM。这应该可以解决问题,因为您的 report-aggregate POM 使用 &lt;dependencies&gt;,而不是 &lt;modules&gt;
  • 在根 POM 中保留 jacoco-maven-plugin 的目标 prepare-agent 的配置。

我建议你看看 JaCoCo 论坛https://groups.google.com/forum/#!topic/jacoco/FpdLbxsXSTY。参考完整的demo集成测试https://github.com/jacoco/jacoco/tree/master/jacoco-maven-plugin.test/it/it-report-aggregate

【讨论】:

  • 是否可以对汇总报告运行 jacoco-check?
  • @tuk 可能,虽然如果你有规则,你想在 JaCoCo 之上使用 SonarQube。
  • @tuk 你能弄明白吗?
猜你喜欢
  • 1970-01-01
  • 2022-06-14
  • 2010-10-18
  • 1970-01-01
  • 1970-01-01
  • 2014-08-29
  • 2019-05-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多