Maven and sonar.coverage.jacoco.xmlReportPaths

Using:

  • sonar-maven-plugin (scanner) 3.7.0.1746
  • SonarCloud.io with same results on Docker image sonarqube:latest

Error:

  • Code coverage is mistakenly reported as 0%.
  • Error message in Maven build is: “[WARNING] No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths=’/Users/desharpe/dev/weblogic-image-tool/installer/imagetool/target/site/jacoco/jacoco.xml’. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml”

Searching the community here, I see very similar posts, all of them appear unresolved, or “it must be your settings” sorts of answers. Having the same (or at least similar issue), I tried and tried various combinations of settings, values, etc. The result seems to show that the sonarsource scanner plugin or the scanner itself is interpreting the value from the pom incorrectly.

With this value (or a whole host of other attempted values) for xmlReportPaths:
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/imagetool/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

mvn sonar:sonar

Running maven with this produces the error (above) with 0% coverage reported. But by adding the -D with the same value, the warning never shows in the log, and the code coverage is reported correctly.

mvn sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/Users/desharpe/dev/weblogic-image-tool/imagetool/target/site/jacoco/jacoco.xml 

The workaround is simple, set Sonar scanner options on the command line, and do not bother with setting them in the POM file. Is this an issue with the Sonar scanner, scanner plugin, or are we doing something wrong in our configuration?

Hi,

What happens when you simply don’t configure the value? This should be picked up automatically in Maven analysis.

 
Ann

I’d say the basic issue can be deduced with just what you’ve provided here.

Look very carefully at the error message it’s printing, which specifies the path you were telling it to use. Then compare that with the value you are setting on the command line. They are different.

1 Like

Nice catch David. Thank you. The issue was my usage of ${basedir} in the Maven POM. Basedir changes as Maven traverses the modules. This might work on a flat project, but needs to be adjusted for sub-modules with xmlReportPaths specified in each module or something generic for all modules.

Also, I tried Ann’s suggestion and found her method to work as well. I switched everything to use the defaults, removed specification of the xmlReportPaths, and let the sensors find the files. Thank you as well Ann.