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



我正在将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

有问题的罐子被放入子模块中,如下所示:

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

jacoco报告是通过项目的整体父POM中的一个块生成的,但是我在这里的子模块中添加了一个覆盖,它应该排除它抱怨的类(依赖项中的类版本(,但它没有任何效果:

<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>

因此,它是专门在jacoco-exec中用于发生冲突的集成测试的,但在报告部分,我在那里添加了include,它应该排除来自JAR的任何类:

<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<includes>
<include>com/jlb/**/*.class</include>
</includes>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report</report>
<report>report-integration</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>

最新更新