Sonarqube code coverage is 0

Hi all,

I’m struggling pretty hard setting up the test coverage in Sonarqube with gradle. I’m using

  • SonarQube: 7.9.3 (build 33349)
  • Code Analyzer for Java version 6.3.2 (build 22818)
  • JaCoCo XML report importer 1.1.0 (build 898)
  • Gradle Plugin in version 3.0

Sonarqube shows me all the time 0% code coverage:


But if i check the jacoco report it’s definitely not 0 :wink:

My build.gradle (I tried to keep only the relevant parts):

buildscript {
    //...
}

plugins {
    id 'java'
    id 'org.sonarqube' version '3.0'
    id 'jacoco'
}

sourceCompatibility = '11'
targetCompatibility = '11'

dependencies {
    //...
}

test {
    finalizedBy jacocoTestReport
    testLogging {
        outputs.upToDateWhen { false }
        showStandardStreams = true
        exceptionFormat = 'full'
    }
}

sonarqube {
    properties {
        property 'sonar.projectKey', 'NAME'
        property 'sonar.host.url', 'https://sonarqube....'
        property 'sonar.projectVersion', project.version
        property 'sonar.language', 'java'
        property 'sonar.core.codeCoveragePlugin', 'jacoco'
        property 'sonar.jacoco.reportPaths', "${buildDir}/jacoco/test.exec"
        property 'sonar.coverage.jacoco.xmlReportPaths', "${buildDir}/reports/jacoco/jacoco.xml"
    }
}
tasks['sonarqube'].dependsOn test

jacocoTestReport {
    reports {
        xml.enabled true
        csv.enabled false
        xml.destination file("${buildDir}/reports/jacoco/jacoco.xml")
    }
}

The location of the exec file is build/jacoco/test.exec and the xml file in build/reports/jacoco/jacoco.xml

I expect that something is wrong with the expected sonar properties or missing a plugin. But tried such a lot of combinations and I checked the documentation and other articles yesterday for couple of hours and was not able to find the issue.

Thanks for your help! Appreciated.

Hi @bluepix,

Welcome to the Community! :smiley:

There’s likely to be a clue to the problem in your scanner-side logs; SonarQube will always log an info or warning message if, for example, it can’t find the coverage files or they’re corrupted. Can you run Gradle with the -i option to get info-level logging and take a look at the logs? Feel free to post them here if you’d like me to take a look.

Regards,

Cameron.

Hi @Cameron,

Thanks for your help. Somehow I didn’t get a notification for your answer. I then tried to continue configuring the project in SonarQube and installed another plugin Build Breaker. Had to restart the server to get it applied.
Afterwards the checks were running fine. I guess the restart did his magic :wink: So basically the problem solved.

Regards,
Simon

Hi Simon,

Glad it’s all working fine :smiley:

Regards,

Cameron.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.