Maven jacoco 排除不起作用

标签 maven configuration jacoco jacoco-maven-plugin

 <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.0</version>
                <configuration>
                    <!-- remove haltOnFailure to purposely fail build once we recover coverage back to 70% -->
                    <haltOnFailure>false</haltOnFailure>
                    <rules>
                        <rule>
                            <element>CLASS</element>
                            <limits>
                                <limit>
                                    <counter>LINE</counter>
                                    <value>COVEREDRATIO</value>
                                    <minimum>0.70</minimum>
                                </limit>
                                <limit>
                                    <counter>BRANCH</counter>
                                    <value>COVEREDRATIO</value>
                                    <minimum>0.70</minimum>
                                </limit>
                            </limits>
                            <excludes>
                                <!-- exclude domain objects -->
                                <exclude>com/path/to/classes/**/*</exclude>                               
                            </excludes>
                        </rule>
                    </rules>
                </configuration>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>check</id>
                        <goals>
                            <goal>check</goal>
                            <goal>report</goal>
                        </goals>
                        <phase>verify</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>

预期行为:target/site/jacoco/index.html 中的 HTML 报告不包含 com/path/to/classes 的行

实际行为: target/site/jacoco/index.html 中的 HTML 报告包括 com/path/to/classes 的一行,这导致覆盖率被报告为(在我的例子中) 32%,证明该包不应该被包含在内。

enter image description here

我一定是做错了什么?

最佳答案

您可以在 configurationexcludes 节点上从 instrumentation/analysis/reports 中完全排除文件

<configuration>
    <excludes>
        <exclude>com/path/to/classes/**/*</exclude>
    </excludes>
</configuration>

rule 节点上指定的排除项仅忽略为该规则排除的类

关于Maven jacoco 排除不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49409582/

相关文章:

java - 服务条目不断从 list 中消失

javascript - CK 编辑器。如何关闭自动增长(设置恒定高度)

java - JPMS/Jigsaw Java 11 Maven 应用程序中的 Keycloak-Admin-Client - 依赖问题

java - %USERPROFILE% 下的 Eclipse Maven 本地存储库设置

tomcat - Hudson - Maven 在 Tomcat-6 - Gentoo 上失败(无法创建/dev/null/.m2)

python - 在python中读写cfg文件

php - 如何为整个项目定义一些常量?

unit-testing - Gradle jacoco 代码覆盖率 - 然后在 Jenkins 中发布/显示

java - NetBeans、Jacoco 和Optional.orElseThrow()

android - Jacoco 代码覆盖 Android Studio 不考虑 androidTest 文件夹