javasonarqubejacocosonarqube5.1sonar-maven-plugin

Sonar reports different line and branch coverage than Idea, Eclipse, Maven and Jenkins


I have all those tools reporting the same coverage with JaCoCo: 69% line coverage and 23% branch coverage.

Note: Screenshots had been taken over several days so they have slightly different values, but the variance is < 1%

Jenkins: jenkins

Maven: maven

Eclipse: eclipse

However Sonar reports different values:

sonar

Maven project is structured as follows:

You can see the same coverage reported on main and java modules, and no coverage for the js one.

Modules

I'm using the latest versions of jacoco, jacoco-maven-plugin and Sonar's Java Plugin.

Here are the relevant build log fragments from mvn sonar:sonar -- all seem to be in order:

$ egrep -i 'jacoco|\[warn]' consoleText
[WARN] [04:34:29.569] 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[WARN] [04:34:29.576] 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[WARN] [04:34:29.593] 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[INFO] [04:34:32.704] JaCoCoItSensor: JaCoCo IT report not found: /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/jacoco-it.exec
[WARN] [04:34:32.952] Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property
[WARN] [04:34:50.101] Cobertura report not found at /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/site/cobertura/coverage.xml
[INFO] [04:35:03.391] Sensor JaCoCoSensor
[INFO] [04:35:03.406] Analysing /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/jacoco.exec
[INFO] [04:35:03.712] Sensor JaCoCoSensor (done) | time=321ms
[INFO] [04:35:03.712] Sensor JaCoCoOverallSensor
[INFO] [04:35:03.714] Analysing /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/jacoco.exec
[INFO] [04:35:03.762] Analysing /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/sonar/jacoco-overall.exec
[INFO] [04:35:03.906] Sensor JaCoCoOverallSensor (done) | time=194ms
[INFO] [04:35:11.013] JaCoCoSensor: JaCoCo report not found : /home/acme/workspace/example-Sonar-DSL/modules/frontend/target/jacoco.exec
[INFO] [04:35:11.013] JaCoCoItSensor: JaCoCo IT report not found: /home/acme/workspace/example-Sonar-DSL/modules/frontend/target/jacoco-it.exec
[INFO] [04:35:11.179] JaCoCoSensor: JaCoCo report not found : /home/acme/workspace/example-Sonar-DSL/target/jacoco.exec
[INFO] [04:35:11.179] JaCoCoItSensor: JaCoCo IT report not found: /home/acme/workspace/example-Sonar-DSL/target/jacoco-it.exec

Is this a bug in Sonar's Java Plugin? I think it's highly unlikely that metric reported by sonar is correct when 3 other tools configured by different people consistently show different values.


Solution

  • It seems like the coverage metric has fixed itself. It now reports correct values -- incidentally we've upgraded JDK to latest patch version (8u92) the same day.

    This suggests the JaCoCo sensor works wrong depending on JRE, but needs more investigation.

    coverage trend