Jacoco gradle plugin adds a magic number to class name

61 views
Skip to first unread message

sergii...@globallogic.com

unread,
Aug 8, 2018, 3:42:00 AM8/8/18
to JaCoCo and EclEmma Users
Hi, I use Gradle 4.9 and Jacoco plugin 0.8.0. When I run jacocoTestCoverageVerification task and some of my classes violate the rule I got the following message in the console:

Task :jacocoTestCoverageVerification FAILED
[ant:jacocoReport] Rule violated for class MyClass.1: instructions covered ratio is 0.0000, but expected minimum is 0.0001

The issue is that I do not have class with name MyClass.1. The only class I have is MyClass.
Jacoco adds number after the class name. And in order to exclude the class I have to write something like this:

jacocoTestCoverageVerification {
violationRules {
rule {
element = 'CLASS'
excludes = [
'MyClass.1'
]
}
}
}
Could anyone help to solve the issue or at least explain the behaviour?

Evgeny Mandrikov

unread,
Aug 8, 2018, 6:47:47 AM8/8/18
to JaCoCo and EclEmma Users
Hi,

In absence of complete reproducer including source file "MyClass.java" , one can only guess what is going on. Can you provide it?

Also why not look at HTML report? which shows names of classes and what is more important links them to the source files from which they were compiled.

And my wild guess is that actual class name is "MyClass$1" and "$" somehow gets converted into "." (wrongly?)
Usually such names are the names of synthetic classes generated by Java compiler - do you have "MyClass$1.class"?
More about synthetic classes in https://github.com/jacoco/jacoco/issues/660
From which you can see that next release of JaCoCo (0.8.2) will provide filter for synthetic classes - https://github.com/jacoco/jacoco/issues/668
So maybe you can also try unreleased version?

repositories {
  maven {
  }
}
jacoco {
  toolVersion = "0.8.2-SNAPSHOT"
}


Regards,
Evgeny

sergii...@globallogic.com

unread,
Aug 9, 2018, 4:36:45 AM8/9/18
to JaCoCo and EclEmma Users
Hi Evgeny,


Thank you for your help. My class contains switch on enum. The same issue is fully described here (https://github.com/jacoco/jacoco/issues/660). Switching to "0.8.2-SNAPSHOT" solved the problem.

Regards,
Sergii

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages