SonarJava 5.13.1.18282 silently ignores JaCoCo XML report

Versions used

  • SonarQube version 6.7.7
  • SonarJava version 5.13.1.18282

The JaCoCoSensor sensor in SonarJava project has deprecated the property sonar.jacoco.reportPaths in favor of sonar.coverage.jacoco.xmlReportPaths which is silently ignored and not analyzed.

To make things worse sonar.coverage.jacoco.xmlReportPaths is defined by default, meaning that if such an XML report exists in any of the default locations (in e.g. target/site/jacoco/jacoco.xml in Maven builds) it will override all deprecated reports (such as jacoco.exec).

Steps to reproduce

The behaviour can be observed in the following Maven setups:

Without sonar.jacoco.reportPaths property

  1. Using jacoco-maven-plugin generate report with the report goal. This generates both an HTML and an XML report.
  2. Invoke sonar-scanner in debug mode, the following log will be printed:
09:33:20.940 INFO: Sensor JaCoCoSensor [java]
09:33:20.944 DEBUG: JaCoCo XML report found, skipping processing of binary JaCoCo exec report.
09:33:20.944 INFO: Sensor JaCoCoSensor [java] (done) | time=4ms
  1. Coverage is set to 0.0% in SonarQube

With sonar.jacoco.reportPaths property

  1. Using jacoco-maven-plugin generate report with the report goal. Once again this generates both and HTML and XML report.
  2. Invoke sonar-scanner in debug mode, the following log will be printed:
09:35:52.190 INFO: Sensor JaCoCoSensor [java]
09:35:52.194 INFO: Both 'sonar.jacoco.reportPaths' and 'sonar.coverage.jacoco.xmlReportPaths' were set. 'sonar.jacoco.reportPaths' is deprecated therefore, only 'sonar.coverage.jacoco.xmlReportPaths' will be taken into account.
09:35:52.194 DEBUG: JaCoCo XML report found, skipping processing of binary JaCoCo exec report.
09:35:52.194 INFO: Sensor JaCoCoSensor [java] (done) | time=4ms
  1. Coverage is once again set to 0.0% in SonarQube.

Workarounds

So far the only workaround I’ve found is by either…

  1. … not generating a report at all (i.e. run only prepare-agent goal) or…
  2. … removing the generated XML report manually

Both are suboptimal solutions, as for debugging purposes we would still like to store the HTML report, but do not want to make workaround steps in our otherwise robust CI pipelines.

Either way, by not having the XML report around we can observe the following log:

09:42:14.172 INFO: Sensor JaCoCoSensor [java]
09:42:14.176 WARN: Property 'sonar.jacoco.reportPaths' is deprecated (JaCoCo binary format). 'sonar.coverage.jacoco.xmlReportPaths' should be used instead (JaCoCo XML format).
09:42:14.197 INFO: Analysing C:\Users\elindqvi\Repositories\service-orchestration\altiplano-driver\target\jacoco.exec
09:42:14.306 INFO: Sensor JaCoCoSensor [java] (done) | time=134ms

and finally get the appropriate coverage percent in SonarQube.

Other workaround is to install sonar-jacoco plugin (which — as far as I can see — has fixed the issue) for SonarQube, but unfortunately I’m not our SonarQube instance administrator.

Maybe a stupid question, but can you ask your instance administrator?

I can. Although in a big company like ours, changes happen very slowly.

You can tell them that support for importing the .exec format at all will be removed in the next major version of SonarJava, so the sooner they let people import the XML format the less pain there will be for them down the line! :smiley:

That aside, I’ll be honest that I also find this a little sub-optimal. However it is also a temporary pain and pushes users to move to the XML format sooner if they’re already generating the correct reports.

hello @Eetami,

do you know why XML report doesn’t produce coverage information in SonarQube? When we deprecated the binary report we designed it this way, because it seems to me that using XML report is always superior to the binary report. So I would like to understand why binary report works and XML report doesn’t in your case.

It’s because SonarJava’s JaCoCoSensor does not actually process the XML report at all, but instead delegates that to JaCoCo plugin that has its own JacocoSensor implementation as well.

Though I feel dumb now that our SonarQube administrator installed the JaCoCo plugin 5 seconds after I sent a support request. So for us this issue is fixed.

I propose that SonarJava plugin would handle the situation by printing a clear notification that JaCoCo plugin is needed for processing XML reports.

Ok, I overlooked that you are on 6.7. where sonar-jacoco is not shipped by default. Indeed this will happen when the plugin processing XML report is missing. We decided to accept it, as it should not concern so many users and there is easy workaround (installing the plugin).

I created following ticket to improve the log message to mention that sonar-jacoco is required to process the XML report

https://jira.sonarsource.com/browse/SONARJAVA-3164

1 Like