Context:
- SonarCube version 8.9.6 (build 50800)
- jacoco-maven-plugin version 0.8.5
- sonar-maven-plugin 3.9.1.2184
- multi-module maven project
Maven project layout:
[root of project]
+-- app
+-- dbsync
+-- mock-rest
Where app
, dbsync
, mock-rest
are child maven modules of the main project pom.xml
config.
The jococo coverage reports are generated appropriately in each sub-module’s respective target
directory and produce a file named jacoco.exec
. For example, there is a file at [root of project]/app/target/jacoco.exec
. If I look in the file (yes, it’s binary but if you squint hard enough there’s some sense to be made of it) I can see the coverage information for my classes.
The problem is that sonar cannot seem to ingest the jacoco.exec
file from a child module.
When enabling the debug logs (-X
argument to maven) I see this in my build output:
[INFO] 16:24:33.859 Sensor Groovy JaCoCo Coverage [groovy]
[INFO] 16:24:33.863 Analysing /tmp/workspace/Apps_sentinel-service_PR-47-K6IY34YRWVSHCRUSXNJFB2CZSZB2WILBQEL2UJV6SFCGMZQ5D3GQ/app/target/jacoco.exec
[INFO] 16:24:33.900 Analysing /tmp/workspace/Apps_sentinel-service_PR-47-K6IY34YRWVSHCRUSXNJFB2CZSZB2WILBQEL2UJV6SFCGMZQ5D3GQ/app/target/sonar/jacoco-overall.exec
[WARNING] 16:24:33.958 File not found: com/optum/cirrus/isl/sentinel/controller/handler/GlobalRestExceptionHandler.java
[WARNING] 16:24:33.958 File not found: com/optum/cirrus/isl/sentinel/service/v1/StreamSink.java
[WARNING] 16:24:33.959 File not found: com/optum/cirrus/isl/sentinel/service/v1/impl/StreamSourceImpl.java
[WARNING] 16:24:33.959 File not found: com/optum/cirrus/isl/sentinel/service/v1/impl/BicycleSizeServiceImpl.java
[WARNING] 16:24:33.959 File not found: com/optum/cirrus/isl/sentinel/config/StreamChannels.java
[WARNING] 16:24:33.960 File not found: com/optum/cirrus/isl/sentinel/exception/BicycleException.java
[WARNING] 16:24:33.960 File not found: com/optum/cirrus/isl/sentinel/service/v1/BicycleSizeService.java
[WARNING] 16:24:33.961 File not found: com/optum/cirrus/isl/sentinel/service/v1/StreamSource.java
[WARNING] 16:24:33.961 File not found: com/optum/cirrus/isl/sentinel/controller/v1/ExampleStreamController.java
[WARNING] 16:24:33.961 File not found: com/optum/cirrus/isl/sentinel/service/v1/impl/StreamSinkImpl.java
[WARNING] 16:24:33.962 File not found: com/optum/cirrus/isl/sentinel/controller/v1/BicycleSizeController.java
[WARNING] 16:24:33.962 File not found: com/optum/cirrus/isl/sentinel/SentinelApplication.java
[WARNING] 16:24:33.962 File not found: com/optum/cirrus/isl/sentinel/health/CustomHealthIndicator.java
[WARNING] 16:24:33.963 Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
[INFO] 16:24:33.963 Sensor Groovy JaCoCo Coverage [groovy] (done) | time=104ms
I’ve searched the internet for this and found the general theme suggesting use of the jacoco report-aggregate
goal (example: https://github.com/SonarSource/sonar-scanning-examples/blob/master/sonarqube-scanner-maven/maven-multimodule/tests/pom.xml#L42). It seems odd to me that I should have to do extra steps to produce a separate aggregate jacoco report just to satisfy sonar when the sonar-maven-plugin is already traversing each maven sub-module and can locate its respective jacoco.exec
file. Thus, I’m hoping someone can suggest a better solution here.
So far as I can tell, it looks like a bug or missing feature in the sonar-maven-plugin
to me. Hopefully it’s just a misconfiguration on my part but I look forward to your replies!