Sonarqube 8.1, Code Coverage branches 0%

Must-share information :

  • Sonarqube 8.1, jacoco, Gitlab, Maven
  • Code coverage on branch “develop” doesn’t work : 0%. Only master branch is work
  • jacoco.exec is ok. we tried :
    • mvn sonar:sonar
    • mvn org.jacoco:jacoco-maven-plugin:prepare-agent sonar:sonar
1 Like

Hi Egar,

You need to configure jacoco:prepare-agent to prepare the maven test phase that generated the target/jacoco.exec. But jacoco:prepare-agent is not needed by the sonar:sonar goal. What sonar:sonar needs it’s the target/site/jacoco/jacoco.xml file generated by the report phase. Do you have this jacoco.xml file? If not, this means that you need to configure jacoco:report.
See [Coverage & Test Data] Importing JaCoCo coverage report in XML format
Then try to run mvn -X sonar:sonar , you should see:

[INFO] 16:59:10.201 Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 16:59:10.201 1/1 source files have been analyzed
[DEBUG] 16:59:10.203 Reading report '/home/user/project/target/site/jacoco/jacoco.xml'
[INFO] 16:59:10.208 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=7ms

Note: you can also provide jacoco xml report path using sonar.coverage.jacoco.xmlReportPaths

And last question: How did you add the branch support to SonarQube? Do you have a commercial edition or the community edition with an additional plugin?

Hi Alban,

Thanks for your response. We have an entreprise Edition.

SonarQube 8.1 Enterprise Edition (like all commercial editions) supports import of coverage on branch analysis.
So if coverage import is working for master branch, it should also work on other branches.
(except if your gitlab sonarqube analysis configuration if different for master branch compare to other branches)
Could you provide more context about your configuration, so we can reproduce your problem?