如何在子项目中添加更多Jacoco排除项? [英] How to add more Jacoco exclusions in a child project?

查看:129
本文介绍了如何在子项目中添加更多Jacoco排除项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在父POM中,我们设置了Jacoco规则以强制执行测试范围.这包括一些通常没有行为的类的排除项:

In a parent POM we have Jacoco rules set up to enforce test coverage. This includes some exclusions for classes that typically don't have behavior:

<execution>
    <id>default-check</id>
    <goals>
        <goal>check</goal>
    </goals>
    <configuration>
        <excludes>
            <!-- exclude largely auto-generated domain and model classes -->
            <exclude>**/model/*.class</exclude>
            <exclude>**/model/**/*.class</exclude>
            <exclude>**/domain/*.class</exclude>
            <exclude>**/domain/**/*.class</exclude>
            <exclude>**/dto/*.class</exclude>
            <exclude>**/dto/**/*.class</exclude>
        </excludes>
        <rules>
            <rule>
                <element>BUNDLE</element>
                <limits>
                    <limit implementation="org.jacoco.report.check.Limit">
                        <counter>INSTRUCTION</counter>
                        <value>COVEREDRATIO</value>
                        <minimum>0.70</minimum>
                    </limit>
                </limits>
            </rule>
        </rules>
    </configuration>
</execution>

在使用该父级的子POM中,添加其他排除类模式的Maven魔术是什么?

In a child POM that uses this parent, what is the Maven magic for adding additional excluded class patterns?

我正在尝试以各种方式使用combine...属性,但无法正确获得有效的POM.

I'm trying to use combine... attributes in various ways but am unable to get the effective POM to come out correctly.

有什么想法吗?

推荐答案

您不能扩展列表,但可以覆盖它.在大多数情况下,您会需要每个模块的排除清单(在不同的模块中,您经常有完全相同的类型吗?)

You can't extend the list but you can overwrite it. Most of the time, you'll want a specific list of exclusions per module (how often do you have the exact same types in different modules?)

为此,请不要在父POM中放入任何排除项.只需将标准/共享执行及其配置放在其中即可.在子POM中:

To do that, don't put any exclusions in the parent POM. Just put the standard/shared executions and their configuration in there. In the child POM:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>

                <configuration>
                    <excludes>
                        <exclude>ch/swissquant/toolbox/exceptions/**/*.class</exclude>
                        <exclude>ch.swissquant.toolbox.exceptions.*</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Maven将读取此配置,并将其与在父POM中找到的所有执行合并(因此它将应用于复杂的Jacoco流程的所有步骤).

Maven will read this configuration and merge it with any execution it finds in the parent POM (so it will be applied to all steps of the complicated Jacoco process).

合并的过程如下:Maven读取父POM,然后用子POM中的任何特定值覆盖它(最后一个条目获胜).对于属性也是如此,因此您可以使用属性为父级中的覆盖率等定义默认值,并在子级中重新定义属性.

The merge works like this: Maven reads the parent POM and then overwrites it with any specific values from the child POM (last entry wins). This is also true for properties, so you can define default values for things like the coverage rations in the parent using properties and redefine the properties in the child.

您可以通过运行mvn help:effective-pom进行验证.

You can verify this by running mvn help:effective-pom.

这篇关于如何在子项目中添加更多Jacoco排除项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆