How to ignore inner static classes in Jacoco when using Gradle

自闭症网瘾萝莉.ら 提交于 2019-12-12 03:16:50

问题


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

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

class A {
    ...

    static class B {
        ...
    }
}

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*"
                    ])
        }))
    }
}

($ 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?


回答1:


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).

So it becomes:

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

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



来源:https://stackoverflow.com/questions/58604955/how-to-ignore-inner-static-classes-in-jacoco-when-using-gradle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!