使用Gradle时如何忽略Jacoco中的内部静态类 [英] How to ignore inner static classes in Jacoco when using Gradle

查看:382
本文介绍了使用Gradle时如何忽略Jacoco中的内部静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何忽略在自己的.java文件中定义的类,但不知道如何忽略内部类.

I know how to ignore classes defined in their own .java files, but not aware of how to ignore inner classes.

例如,我有一个带有嵌套类B的类A:

For example, I have class A with nested class B:

class A {
    ...

    static class B {
        ...
    }
}

jacocoTestReport会使用以下语法在jacoco.gradle文件中忽略它们时继续检查覆盖范围(从这篇文章中了解到:

jacocoTestReport keeps checking the coverage when I want to ignore them in jacoco.gradle file with this syntax(learned from this post: How to ignore inner/nested classes with JaCoCo?): (setFrom part is for later versions of Gradle, where classDirectories = files() is deprecated)

apply plugin: "jacoco"

jacoco {
    toolVersion = "0.8.3"
}

jacocoTestReport {
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it,
                    exclude: [
                            "com/example/xxx/*",
                            "com/example/xxx/A\$.*B*"
                    ])
        }))
    }
}

($必须转义,而在帖子中则不需要,因为当我使用Gradle时他使用Maven)

($ must be escaped, while in the post there is no need because he uses Maven when I use Gradle)

那么,我该如何忽略这个内部类?

So, how can I ignore this inner class?

推荐答案

最后,我找到了几次尝试失败的答案.如另一篇文章所述,命名模式似乎遵循编译的Java类的命名约定,并且在外部类和内部类之间不需要. .因此,它应该类似于A$B.而且,可能会有一些.class干扰(我的猜测),所以我添加了A$B*(对于其他普通类,不需要最后一个*).

At last I found the answer with several trial-and-failure. Seems that the naming pattern follows compiled Java classes naming convention, as mentioned in the other post, and will not require the . between the outer class and the inner class. So, it should be like A$B. And, there may be some .class interfering(my guess), so I added A$B*(for other normal classes, last * is not needed).

它变成:

"com/example/xxx/A\$B*"

我希望有一些有关这种排除模式的文档.还没有.

I hope there be some documentation about this pattern of exclusion. There is not, yet.

这篇关于使用Gradle时如何忽略Jacoco中的内部静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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