gpt4 book ai didi

java - Maven & JaCoCo - 如何从依赖项引入的报告中排除类?

转载 作者:行者123 更新时间:2023-12-01 16:59:54 24 4
gpt4 key购买 nike

我正在将 JaCoCo 添加到项目中,并且我正在努力让它从子模块的报告中排除一个类(通过依赖项引入)。这是我收到的错误:

Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.7.1:site (default-site):
Error generating jacoco-maven-plugin:0.8.4:report:
Error while creating report:
Error while analyzing ~/proj/submod/target/classes/mydep-jar-with-dependencies.jar@com/jlb/proj/pkg/MyClass.class. Can't add different class with same name: com/jlb/proj/pkg/MyClass

并且有问题的 jar 被带入子模块,如下所示:

<dependencies>
<dependency>
<groupId>com.jlb.pkg</groupId>
<artifactId>mydep</artifactId>
<version>${revision}</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
</dependencies>

jacoco 报告是通过项目的整体父 POM 中的一个 block 生成的,但是我在此处的相关子模块中添加了一个覆盖,这应该排除其提示的类(依赖项中的类的版本) ,但没有效果:

  <reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
<report>report-integration</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<excludes>
<exclude>**/com/jlb/proj/pkg/MyClass.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</reporting>

那么如何从报告中排除有问题的类呢?

最佳答案

请尝试 com.jlb.pkg 应该是您的基础包将 jacoco 报告生成与 Maven 构建的测试阶段联系起来

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<includes>
<include>com/jlb/pkg/**/*</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

关于java - Maven & JaCoCo - 如何从依赖项引入的报告中排除类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61526040/

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