"No coverage information was collected." when running 'gradle sonarRunner' after generating Jacoco reports

I 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 added the jacoco plugin to my build.gradle file in empty to see the unit test coverage results and I see a warning:

No coverage information was collected. Perhaps you forgot to include debugging information in the compiled classes?

I am currently running version 4.3.2 Sonar and this is what I see 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 I'm missing? Surprisingly, there doesn't seem to be much information about creating unit test coverage with Sonar using Gradle.

+3


source to share


1 answer


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

jacoco {
    toolVersion = "0.7.0.201403182114"
}

      



Also, you have to make sure your sonar version supports jdk8

+1


source







All Articles