chazzlabs
chazzlabs

Reputation: 113

"Coverage information was not collected." when running 'gradle sonarRunner' after generating Jacoco reports

I've started with the 'java-gradle-simple' example from the Sonar GitHub repo:

https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/gradle/java-gradle-simple

I've added the jacoco plugin to my build.gradle file in an empty to see unit test coverage results, and I'm seeing the warning:

Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?

I'm currently running version 4.3.2 of Sonar, and this is what I'm seeing after running 'gradle test jacocoTestReport sonarRunner':

Sonar report

My build.gradle file looks like this:

apply plugin: 'java'
apply plugin: 'sonar-runner'
apply plugin: 'jacoco'

allprojects {  
  ext.baseVersion = "0.1"
  ext.snapshotVersion = true

  group = "org.sonar.tests"
  version = "$baseVersion" + (snapshotVersion ? "-SNAPSHOT" : "")
}

sonarRunner {
    sonarProperties {
        property "sonar.projectName", "Simple Java Gradle Project"
        property "sonar.projectKey", "org.codehaus.sonar:example-java-gradle"
        property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
        property "sonar.binaries", "${project.buildDir}/classes"
        property "sonar.sources", "src/main"
        property "sonar.tests", "src/test"
        property "sonar.java.coveragePlugin", "jacoco"
    }
}

buildscript {
    repositories { mavenCentral() }
    dependencies { classpath 'org.ajoberstar:gradle-jacoco:0.1.0' }
}

test {
  ignoreFailures = true
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.10'
}

repositories {
    mavenCentral()
}

Is there some other configuration that I'm missing? Surprisingly, there doesn't seem to be much information on generating unit test coverage with Sonar using Gradle.

Upvotes: 4

Views: 3577

Answers (1)

Stav Saad
Stav Saad

Reputation: 599

Since you are using jdk 8, you should add the following block to your gradle script:

jacoco {
    toolVersion = "0.7.0.201403182114"
}

Also, you should make sure your sonar version supports jdk8

Upvotes: 1

Related Questions