JaCoCo coverage report delivery

Must-share information (formatted with Markdown):

  • which versions are you using: sonarqube:10.4.1-community
  • how is SonarQube deployed: Docker
  • what are you trying to achieve: receive JaCoCo coverage reports on SonarQube server
  • what have you tried so far to achieve this: multiple attempts of delivery and display

Hello,

I am having issues deliverying the JaCoCo coverage reports to SonarQube.

The JaCoCo report is being generated during the Maven test phase, in the Quarkus workflow. Manually checking the report, it seems to be complete. A jacoco.xml file is also present.

I am triggering the Sonar scan via mvn sonar:sonar, providing all the required parameters for performing and delivering the analysis to the server, including the sonar.coverage.jacoco.xmlReportPaths parameter that is set to the path of the jacoco.xml file.

Running the analysis with the additional --debug parameter, I also see that the scanner recognizes the generated report and reads it:

[INFO] 13:46:38.453 Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 13:46:38.460 Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[DEBUG] 13:46:38.460 Reading report '/opt/jenkins/workspace/sonarqube/analysis-webhook/heating-fuels-service/./target/jacoco-report/jacoco.xml'
[INFO] 13:46:38.717 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=264ms

However, after the analysis is performed and marked as a success, I cannot find the JaCoCo coverage report on the respective SonarQube project, not in the New Code nor the Overall Code section. The Overall Code coverage specifically seems to be much higher than what the JaCoCo report claims when reading it on the filesystem, making me assume that the coverage shown on SonarQube is actually Sonar’s own coverage, not JaCoCo’s.

If it’s relevant in any way, I am also using the community branch plugin 1.19.0 until we upgrade to the Developer or Enterprise edition.

Is the report delivered to the server but is located on some other part of the UI? Should I be trying to deliver it in some other way? Perhaps something else entirely?

Hi,

You’re not going to find the JaCoCo report in SonarQube as such. Coverage reports aren’t “uploaded” to SonarQube; they’re read by analysis & their values aggregated (if there are multiple) and displayed in SonarQube.

SonarQube goes strictly by what your reports tell it. No reports; no coverage. While it’s quite possible for coverage to show up lower in SonarQube that in your reports, higher is surprising. Are you providing multiple reports to analysis? Because what you see in SonarQube is an aggregation of all reports.

 
HTH,
Ann

Hey @ganncamp,

Thank you for your response.

The only report that is explicitly provided is the JaCoCo report in the form of a single jacoco.xml file. Considering the project in question is a single-module project, it is a non-aggregated JaCoCo report.

These are the differences between opening up a HTML index of a JaCoCo report on the filesystem, and opening the Coverage page on SonarQube:

Since the debug logs are quite extensive, I have taken out only a portion here that looks relevant. If some other logs might be crucial as well, please, let me know:

[INFO] 13:28:58.334 100% analyzed
[INFO] 13:28:58.334 Batch processing: Done.
[INFO] 13:28:58.337 Did not optimize analysis for any files, performed a full analysis for all 29 files.
[INFO] 13:28:58.337 No "Generated" source files to scan.
[INFO] 13:28:58.337 Sensor JavaSensor [java] (done) | time=8840ms
[INFO] 13:28:58.337 Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 13:28:58.344 Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[DEBUG] 13:28:58.344 Reading report '/opt/jenkins/workspace/sonarqube/analysis-webhook/heating-fuels-service/./target/jacoco-report/jacoco.xml'
[INFO] 13:28:58.585 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=248ms
[INFO] 13:28:58.585 Sensor CSS Rules [javascript]
[INFO] 13:28:58.586 No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[INFO] 13:28:58.586 Sensor CSS Rules [javascript] (done) | time=1ms
[INFO] 13:28:58.587 Sensor C# Project Type Information [csharp]
[INFO] 13:28:58.588 Sensor C# Project Type Information [csharp] (done) | time=1ms
[INFO] 13:28:58.588 Sensor C# Analysis Log [csharp]
[INFO] 13:28:58.608 Sensor C# Analysis Log [csharp] (done) | time=20ms
[INFO] 13:28:58.608 Sensor C# Properties [csharp]
[DEBUG] 13:28:58.608 Project 'digital-services_heating-fuels-service': No Roslyn issues reports have been found.
[INFO] 13:28:58.608 Sensor C# Properties [csharp] (done) | time=0ms
[INFO] 13:28:58.608 Sensor SurefireSensor [java]
[INFO] 13:28:58.610 parsing [/opt/jenkins/workspace/sonarqube/analysis-webhook/heating-fuels-service/target/surefire-reports]
[INFO] 13:28:58.810 Sensor SurefireSensor [java] (done) | time=202ms
[INFO] 13:28:58.810 Sensor HTML [web]
[INFO] 13:28:58.814 Sensor HTML [web] (done) | time=4ms
[INFO] 13:28:58.815 Sensor XML Sensor [xml]
[DEBUG] 13:28:58.819 'pom.xml' generated metadata with charset 'UTF-8'
[INFO] 13:28:58.823 1 source file to be analyzed
[DEBUG] 13:28:58.963 Count lines in file:///opt/jenkins/workspace/sonarqube/analysis-webhook/heating-fuels-service/pom.xml
[INFO] 13:28:59.056 1/1 source file has been analyzed
[INFO] 13:28:59.056 Sensor XML Sensor [xml] (done) | time=242ms
[INFO] 13:28:59.056 Sensor TextAndSecretsSensor [text]
[INFO] 13:28:59.578 79 source files to be analyzed
[INFO] 13:29:00.880 79/79 source files have been analyzed
[INFO] 13:29:00.881 Sensor TextAndSecretsSensor [text] (done) | time=1824ms
[INFO] 13:29:00.881 Sensor VB.NET Project Type Information [vbnet]
[INFO] 13:29:00.882 Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
[INFO] 13:29:00.882 Sensor VB.NET Analysis Log [vbnet]
[INFO] 13:29:00.900 Sensor VB.NET Analysis Log [vbnet] (done) | time=18ms
[INFO] 13:29:00.900 Sensor VB.NET Properties [vbnet]
[DEBUG] 13:29:00.900 Project 'digital-services_heating-fuels-service': No Roslyn issues reports have been found.
[INFO] 13:29:00.900 Sensor VB.NET Properties [vbnet] (done) | time=0ms
[INFO] 13:29:00.900 Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor
[INFO] 13:29:00.901 Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor (done) | time=1ms
[INFO] 13:29:00.901 Sensor IaC Docker Sensor [iac]
[INFO] 13:29:00.905 0 source files to be analyzed
[INFO] 13:29:01.003 0/0 source files have been analyzed
[INFO] 13:29:01.004 Sensor IaC Docker Sensor [iac] (done) | time=103ms
[INFO] 13:29:01.008 ------------- Run sensors on project
[DEBUG] 13:29:01.110 'Generic Coverage Report' skipped because one of the required properties is missing
[DEBUG] 13:29:01.110 'Import external issues report from SARIF file.' skipped because one of the required properties is missing
[DEBUG] 13:29:01.110 'C#' skipped because there is no related file in current project
[DEBUG] 13:29:01.111 'C# File Caching Sensor' skipped because there is no related file in current project
[DEBUG] 13:29:01.111 'C# Tests Coverage Report Import' skipped because there is no related file in current project
[DEBUG] 13:29:01.111 '[Deprecated] C# Integration Tests Coverage Report Import' skipped because there is no related file in current project
[DEBUG] 13:29:01.112 'C# Unit Test Results Import' skipped because there is no related file in current project
[DEBUG] 13:29:01.112 'VB.NET' skipped because there is no related file in current project
[DEBUG] 13:29:01.112 'VB.NET File Caching Sensor' skipped because there is no related file in current project
[DEBUG] 13:29:01.113 'VB.NET Tests Coverage Report Import' skipped because there is no related file in current project
[DEBUG] 13:29:01.113 '[Deprecated] VB.NET Integration Tests Coverage Report Import' skipped because there is no related file in current project
[DEBUG] 13:29:01.113 'VB.NET Unit Test Results Import' skipped because there is no related file in current project
[DEBUG] 13:29:01.114 Sensors : Analysis Warnings import -> Zero Coverage Sensor -> Java CPD Block Indexer
[INFO] 13:29:01.114 Sensor Analysis Warnings import [csharp]
[INFO] 13:29:01.115 Sensor Analysis Warnings import [csharp] (done) | time=1ms
[INFO] 13:29:01.115 Sensor Zero Coverage Sensor
[INFO] 13:29:01.116 Sensor Zero Coverage Sensor (done) | time=1ms
[INFO] 13:29:01.116 Sensor Java CPD Block Indexer

Thank you for any sort of assistance.

Hi,

Here’s something interesting:

Selection_2007

versus:

Selection_2008

It seems that the calculations are different because the inputs are different. You should compare what JaCoCo is looking at as coverable versus what’s configured for SonarQube.

 
HTH,
Ann