【问题标题】:Maven jacoco excludes does not workMaven jacoco 排除不起作用
【发布时间】:2018-03-21 14:53:58
【问题描述】:
 <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%,证明这个包被包含不应该

我一定是做错了什么?

【问题讨论】:

    标签: maven configuration jacoco jacoco-maven-plugin


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢 - 没有注意到我错误地将我的 &lt;excludes&gt; 块包含在我的 &lt;rules&gt; 块中,而不是在我的 &lt;configuation&gt; 块下。感谢您的指点(尽管我的配置需要位于嵌套在 &lt;excludes&gt; 父级内的 &lt;exclude&gt; 行中才能正常工作)。
    猜你喜欢
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 2019-11-13
    • 2017-08-14
    • 1970-01-01
    • 2019-01-04
    • 1970-01-01
    相关资源
    最近更新 更多