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

标签 java 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

并且有问题的 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/

相关文章:

java - Maven 忽略 "maven-compiler-plugin"要求

java - Jacoco 覆盖率和 Kotlin 默认参数

gradle - SonarQube和Jacoco之间的线路覆盖范围不同

java - 为什么ZonedDateTime和Calendar在2050年的小时数上不一致?

java - 在什么时候值得在Java中重用数组?

java - Apache Camel 测试在使用camel-archetype-blueprint 创建的项目中失败

java - spring-framework-bom :jar:4. 0.1.RELEASE 的 netbeans maven Web 应用程序中的依赖项解析异常

Intellij IDEA 13.1 Java编译错误

java - 需要使用 jacoco.exec 文件生成代码覆盖率报告

java - 双击 map fragment 的缩放功能