gpt4 book ai didi

java - 使用报告聚合报告和合并多模块 jacoco 报告

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:47:17 33 4
gpt4 key购买 nike

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

最佳答案

抱歉,如果回答晚了。

我假设您的根 pom.xml 是一个聚合器,带有 <modules>module1 组成, module2 , 和 report-aggregate .这就是你遇到麻烦的原因:因为你的根 pom.xml 是一个聚合器,它在你的子模块运行之前运行 JaCoCo,所以你的最终报告是空的。你应该:

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

我建议你看看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 .

关于java - 使用报告聚合报告和合并多模块 jacoco 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50806424/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com