Jacoco Code Coverage is shown as 0% after SonarQube server update

Sonarqube Server: 6.7.7 LTS (Upgraded from 6.7 LTS)
DB: MySQL
Env: EC2, t2.large | Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-1088-aws x86_64)
Projects Run for Analysis: Java | Spring boot
SonarJava: 5.13.1 (build 18282)

I updated the Sonarqube server from 6.7 LTS to 6.7.7 LTS a few days ago. Everything went well and the update was successful.

Actual way of updating:

  1. Upgraded the server in the traditional way. Download the sonarqube set-up, paste it in a folder.
  2. Stop the old version, copy the configs. Start the server from the new folder
  3. Once started, the sonarqube will ask for DB migration tapping on OK, the DB migration completes and sonarqube will become live.

Problem:

  • After the update, I’m not able to see the code coverage for the projects that are run newly.
  • This means I was able to see the code coverage for a project and I ran the Jenkins job to update the code coverage. Now, the code coverage is showing 0%.
  • I can see locally on my machine that the code coverage is more than 50%. But not on the SonarQube server.

Solutions tried so far:

  • I thought the sonar properties are not set correctly and did some tweaks. - NO HELP
  • I thought changing the project key will resolve the problem - NO HELP
  • I thought of setting up SonarQube on my local machine and run the analysis - VOILA, CODE COVERAGE WAS SHOWN.
  • Just to make sure again, I ran a project which had a Code coverage of about 30% on the EC2 instance (where I’m having the problem) - Code coverage turned to 0%. Ran the same job on my local machine, code coverage showed as 30%

I’m unable to find the root cause for this since if it was a DB migration problem, all the projects should have been 0% regardless of the analysis was done prior to server update or later.

Please enlighten me to resolve this problem.

1 Like

hello,

do you create XML coverage report during your build? If so, you will need sonar-jacoco plugin to process XML report. This plugin is included by default in newer versions of SonarQube, but you will miss it in 6.7.x version.

If this doesn’t fix your issue, try to run your analysis with debug logs enabled, and post them here.

1 Like

You are a lifesaver!! The issue got resolved after I installed the plugin

@saberduck I’m relieved that the issue is resolved. But I’ve one doubt. I ran the same code in my local without having to install the sonar-jacoco plugin and it still showed the code coverage. Any idea how did it work? I’m double checked just now that it’s not installed on my local machine.

It depends whether you create XML report or not. There is still deprecated functionality available in SonarJava to read binary exec report for coverage. However, when it detects that there is also XML report created, it will not read the binary report, but delegate to the jacoco plugin to read the XML report.
If there is no XML report, it will read the binary report to provide coverage.

This is a temporary mechanism while both binary and XML reports are supported to avoid the coverage report to be submitted two times. While it sounded like good idea when we developed it, in retrospect I think it was a mistake, because it causes too much confusion. Hopefully we will be able to drop support for reading binary reports soon.

1 Like

Thanks a lot for the explanation.

Hi SonarSource team,
I am using version 6.7.5 of SonarQube and Jacoco Agent 0.8.2 on the app servers, and I am facing similar issue to the above user, my other metrics like code smells get published, but “Code Coverage” is zero percent.

I have noticed that when I run mvn sonar:sonar from my laptop to publish report from my jacoco.exec, I get the following non-critical error regarding Lizard Report:

[INFO] Sensor Cobertura [backelitesonarswiftplugin] (done) | time=0ms
[INFO] Sensor Lizard [backelitesonarswiftplugin]
[INFO] Processing complexity report
[ERROR] Lizard Report not found /home/kram/C_C/trial2/app/appReportMetaDataLibrary/sonar-reports/lizard-report.xml
java.io.FileNotFoundException: /home/kram/C_C/trial2/app/appReportMetaDataLibrary/sonar-reports/lizard-report.xml (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
...
...
[INFO] Saving results of complexity analysis
[INFO] Sensor Lizard [backelitesonarswiftplugin] (done) | time=1ms
[INFO] Sensor FindBugs Sensor [findbugs]

I am interested in knowing:

  1. Why does it look for the xml report, when I have the binary exec data available? Has publishing from exec data been deprecated?
  2. If deprecated, where can I enable the Lizard report?
  3. If not deprecated, how do I force sonar to look only at the exec file?
    Thanks in advance.

Vignesh I am facing whatever you have faced when implementing sonarqube.

However I am unable to succeed even with the solution provided. I have small confusion on the solution provided.

Should we add under

<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

like this?

Should I do anything more. Kindly help

Vignesh I am facing whatever you have faced when implementing sonarqube.

However I am unable to succeed even with the solution provided. I have small confusion on the solution provided.

Should we add under :

<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

like this?

Should I do anything more. Kindly help

See: JaCoCo coverage is 0% on SonarQube

Hi, @Vignesh I am trying to integrate Sonarqube with the Github repository. Have set up Jenkins job and it is success, but code coverage shows 0.0% (unit test says 80)

Hello @Akanksha_Singhal,
This thread is closed, can you open a new one for your problem please.