You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JaCoCo报告显示已排除类0%覆盖率,如何彻底隐藏这些包?

解决JaCoCo报告仍显示已排除包的问题

你当前的问题是只在JaCoCo插桩阶段配置了排除规则,但报告生成和Jenkins展示环节没有同步过滤这些类,所以被排除的包依然会以0%覆盖率出现在报告里。需要从以下两方面修改配置:

1. 更新pom.xml的JaCoCo插件配置

在default-report执行阶段同样添加排除规则,确保Maven生成报告时直接过滤掉目标包:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.5</version>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <excludes>
                    <exclude>com/Abc/Bcd/Cde/**</exclude>
                </excludes>
            </configuration>
        </execution>
        <execution> 
            <id>default-report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <!-- 添加报告阶段的排除配置 -->
            <configuration>
                <excludes>
                    <exclude>com/Abc/Bcd/Cde/**</exclude>
                </excludes>
            </configuration>
        </execution>
    </executions>
</plugin>

注意用**代替*,可以匹配目标包下所有子目录和类文件,过滤更彻底。

2. 配置Jenkinsfile中的JaCoCo步骤

在Jenkins的jacoco步骤里添加excludes参数,让Jenkins展示报告时也过滤掉这些类:

if(runJaCoCo){
    stage('JaCoCo'){
        jacoco(
            excludes: ['com/Abc/Bcd/Cde/**']
        )
    }
}

完成上述修改后,重新触发构建,Jenkins中的JaCoCo报告就不会再显示已排除的Cde包了。

内容的提问来源于stack exchange,提问作者Ricardo Quino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 13:50:48