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
Using jacoco-maven-plugin generate report with the report goal. This generates both an HTML and an XML report.
Invoke sonar-scanner in debug mode, the following log will be printed:
Using jacoco-maven-plugin generate report with the report goal. Once again this generates both and HTML and XML report.
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
Coverage is once again set to 0.0% in SonarQube.
Workarounds
So far the only workaround Iāve found is by eitherā¦
⦠not generating a report at all (i.e. run only prepare-agent goal) orā¦
⦠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.
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!
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.
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 donāt think there is an easy workaround.
Iām on SonarQube 6.7.1. The JaCoCo plugin available in Marketplace is 1.1.0 (build 898). When I try to install it says: āError while downloading plugin ājacocoā with version ā1.1ā. No compatible plugin found.ā
So Iām stuck. I canāt use neither javococo.exec nor jacoco.xml.