"Coverage information was not collected." when running the sonar-runner plugin

I’m using the gradle-2.1/samples/sonarRunner/quickstart project to try to get a simple project running that will show me code coverage in Sonar, and I’m getting the warning " Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?" I’ve tried looking at the code coverage exmamples using Jacoco and applied the jacoco plugin to generate “build/jacoco/test.exec”, but I’m still seeing the warning and a “-” under Unit Tests Coverage in Sonar.

I’m running “gradle test jacocoTestReport sonarRunner”.

Is there something I’m missing when running this plugin?

Here’s the simple build.gradle:

apply plugin: "java"
apply plugin: "jacoco"
apply plugin: "sonar-runner"
  sonarRunner {
    sonarProperties {
    }
}
  repositories {
    mavenCentral()
}
  dependencies {
    compile "commons-collections:commons-collections:3.2"
    testCompile "junit:junit:4.+"
}

You probably have to set some properties to specific values. You should check http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests+for+Java+Project for information on the various coverage properties.

I happened upon this Stack Overflow post that references this warning message and suggests a solution:

http://stackoverflow.com/questions/22174501/sonarqube-not-picking-up-unit-test-coverage

Coverage information was not collected. Perhaps you forget to include debug information into compiled classes? Indicates that the sonar.binaries property was set correctly, but those files were not compiled in debug mode, and they need to be

I can’t verify whether this works, however, because I can’t figure out how to compile my files in debug mode as the SO user suggests.

tracking code coverage should be done automatically with having jacoco + sonar-runner plugin applied. there is no need for further configuration as the sonar-runner plugin adapts its setting automatically when jacoco is applied. which sonar version are you using?

I’m running Sonar version 4.3.2.

Apparently the version of jacoco that Gradle currently uses requires JDK7, and I’ve been using JDK8. After switching to JDK 7 to test this, I’m now able to see unit test coverage on my local Sonar instance.

Is there a proper resolution for this? Is it possible to set the version of jacoco that Gradle is using?

you can specify the jacoco version gradle should use explicitly by adding

  jacoco {

toolVersion = “0.7.2.201409121644” }

After setting my JDK to 8 again, it seems that explicitly setting the jacoco version leaves me with my original issue.

It turns out that the version of the Sonar Java plugin that was being used by my Sonar installation did not support Java 8. Updating the plugin resolved my issue.

I can see the missing code coverage when running with sonar 3.1.1 but it works with sonar 3.7.4 and sonarqube 4.5.1.

Which version are you using?

Sonar 4.3.2. My installation was using version 2.1 of the Sonar Java plugin, and updating that to 2.5.1 did the trick. Apparently 2.1 added Java 8 support, but there were also significant changes involving the Jacoco plugin (I believe in version 2.4) that rolled it into the Java plugin, so perhaps that was my issue.