1

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?

WesternGun
  • 11,303
  • 6
  • 88
  • 157

1 Answers1

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.

WesternGun
  • 11,303
  • 6
  • 88
  • 157
  • It doesn't seem to be working for me, can you provide an example of how did you do it? – Raj Suvariya May 27 '20 at 05:14
  • Hi, just use the pattern; maybe you have some simple repo for me to debug? Just a sample project in github would be nice. (And by simply creating a sample project may solve your problem, my personal exp) – WesternGun May 27 '20 at 09:26