java - Jacoco 无法在 pom.xml 中使用 <exclude> 排除某些包和类

标签 java pom.xml jacoco-maven-plugin

我试图从 Jacoco 覆盖范围中排除某些包和类,因为它们已被弃用。我尝试在 Jacoco 插件中添加 exclude ,如下所示,但是当我查看 Jenkins 上的 Jenkins 报告时,我看到所有这些类也未涵盖,以及包含它们的行数。

这是我想要忽略的内容的目录结构。

com/dir1/dir2/dir3/dir4/dir5/XYZScreeningTask.java
com/dir1/dir2/dir3/dir4/dir6/dir7/XYZScreeningData.java
com/dir1/dir2/dir3/dir4/dir8/xyzscreening/BaseXYZFileProcessor.java
com/dir1/dir2/dir3/dir4/dir8/xyzscreening/XYZScreeningFileProcessor.java
com/dir1/dir2/dir3/dir4/dir8/abccmcactivity/AbcCMSActivityProcessor.java

这是在插件下添加的模式

<excludes>
    <exclude>com/dir1/dir2/dir3/dir4/**/*xyz*/**</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/**/*XYZ*.*</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/**/*abc*/**</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/**/*Abc*.*</exclude>
</excludes>

这是已添加排除项的插件信息。

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <configuration>
                    <excludes>
                        <exclude>com/dir1/dir2/dir3/dir4/**/*xyz*/**</exclude>
                        <exclude>com/dir1/dir2/dir3/dir4/**/*XYZ*.*</exclude>
                        <exclude>com/dir1/dir2/dir3/dir4/**/*abc*/**</exclude>
                        <exclude>com/dir1/dir2/dir3/dir4/**/*Abc*.*</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>instrument</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>restore</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>restore-instrumented-classes</goal>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>pre-unit-test</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>post-unit-test</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>

最佳答案

作为 excludes 的 Jacoco 文档说

A list of class files to exclude from the report. May use wildcard characters (* and ?). When not specified nothing will be excluded.

您需要指定已编译类的类路径。我无法在您想要排除的文件和包中看到模式,因此如果您想排除特定的类。

<excludes>
    <exclude>com/dir1/dir2/dir3/dir4/dir6/dir7/XYZScreeningData.class</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/dir8/xyzscreening/BaseXYZFileProcessor.class</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/dir8/xyzscreening/XYZScreeningFileProcessor.class</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/dir8/abccmcactivity/AbcCMSActivityProcessor.class</exclude>
</excludes>

尽管如此,我们可以通过以下方式排除完整的包,

<exclude>com/dir1/**/*</exclude>

有关通配符的更多信息可以从 here 找到和 here 。上面说。

* matches zero or more characters
** matches zero or more directories
? matches a single character

关于java - Jacoco 无法在 pom.xml 中使用 <exclude> 排除某些包和类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68599401/

相关文章:

java - 如何在jacoco中配置classDumpDir?

java - 在 maven 中配置 JaCoCo 时遇到问题

java - 不显示对象标签,仅显示其 JAXB 属性

java - 实体模型或Pojo类作为REST API的返回对象

java - 如何在java SWING面板中添加Scrollable(滚动条组件)复选框?

java - 如何在没有artifactory或setting.xml的情况下使用Maven项目?

java - 源和目标的 Maven 编译器插件 jdk 版本

maven - 如何在 maven pom 中设置环境变量?

java - jacoco 仅显示同一模块中类的覆盖率

java - Ubuntu 上的 Desktop.getDesktop().open(file) 无法正常工作