Cobertura always uses default value target/site/coverage.xml path when running Sonar Scanner

SonarQube version: 7.9.1 LTS
SonarFlex plugin: 2.5.1

SonarQube Scanner for Jenkins plugin: 2.9

Jenkins job:
JDK: 1.8_151
Sonar Scanner 4.0.0

For all our jobs that define the paths to the Cobertura reports via sonar.flex.cobertura.reportPaths, we’ve noticed that during analysis the Sonar Scanner will default back to using the target/site/coverage.xml path value:

For example in the Jenkins job config we’ve defined this in the Analysis Parameters field:


But during the Sonar Analysis this value is ignored and the default value is used

INFO: Sensor CoberturaSensor [cobertura]
WARN: Cobertura report not found at /var/lib/jenkins/jobs/BlackCatMaster-Sonar/workspace/target/site/cobertura/coverage.xml
INFO: Sensor CoberturaSensor [cobertura] (done) | time=0ms

The full path it should be looking for is:

There’s no default value for sonar.flex.cobertura.reportPaths, at least none is set by the analyzer itself.

Just a wild guess: do you have a file in your project?

Thanks for the quick response @pynicolas!

I did find an old file in the project repo that’s a few years old. The sonar.flex.cobertura.reportPaths property was not defined in the file. I removed the file from the repo and rebuilt but still seeing the same functionality.

I actually think it’s coming from the sonar-cobertura-plugin-2.0.

To test I uninstalled the Cobertura plugin from Sonar. Then rebuilt the Jenkins job and no longer see CoberturaSensor being called in the output, however still don’t have coverage % metrics on the sonar project page.

Interestingly I reinstalled the Cobertura plugin, then added a step in the Jenkins job to copy the coverage.xml from our path to the “default” one specified in the warning and now see Coverage % metrics on the Sonar project page, also see this in the Sonar Scanner output:

INFO: Sensor CoberturaSensor [cobertura]
INFO: parsing /var/lib/jenkins/jobs/BlackCatMaster-Sonar/workspace/target/site/cobertura/coverage.xml
INFO: Sensor CoberturaSensor [cobertura] (done) | time=445ms

So that’s a workaround for our projects that generate a single coverage report. However this won’t work for some of our jobs that generate multiple coverage.xml’s.

I ended up getting it to work.

I set the report path using the old sonar.cobertura.reportPath property and it worked:


Jenkins output during sonar scanner analysis:

INFO: Sensor CoberturaSensor [cobertura]
INFO: parsing /var/lib/jenkins/jobs/BlackCatMaster-Sonar/workspace/blackcat/blackcat-core/target/site/cobertura/coverage.xml
INFO: Sensor CoberturaSensor [cobertura] (done) | time=1001ms

However this property only works for a single path, not multiple comma-separated coverage.xml paths.

Indeed, I didn’t see that the logs you gave us in the first message were not issues by the Flex analyzer.

If you have multiple report files, I suggest that you use sonar.flex.cobertura.reportPaths instead of sonar.cobertura.reportPath. If it doesn’t give you the expected result, check the logs and see if you can find something like:

INFO: Sensor Flex Cobertura [flex]
INFO: Analyzing Cobertura report: coverage.xml
INFO: Sensor Flex Cobertura [flex] (done) | time=16ms

I actually don’t see the Flex Analyzer Sensor being called in the output. We have sonar.flex.cobertura.reportPaths set, is there any other required properties that need to be set in order to have the Flex Sensor called?

Possible problems I can imagine:

  • The Flex analyzer is not installed
  • There’s no file in your project which is considered as a Flex source file

If you run the analysis in debug mode, do you see something like the following?

DEBUG: Declared extensions of language Flex were converted to sonar.lang.patterns.flex : **/*.as
DEBUG: 'Flex' skipped because there is no related file in current project
DEBUG: 'Flex Cobertura' skipped because there is no related file in current project

That’s the issue, the Cobertura coverage xmls are generated from Java source code, not Flex. Searched this doc for Cobertura and only saw the Flex and Python options:

Which Sonar property should be used to specify multiple cobertura coverage.xml report paths for Java?

Instead of running the SonarQube Scanner post-build step, I ended up integrating Sonar analysis into the Maven build step by adding “sonar:sonar” to the maven goals and options field (after setting the global settings mentioned in the SonarScanner for Maven doc), all the cobertura coverage.xmls are now automatically discovered.

Thanks for your help!

I don’t think that there’s a way to specify multiple Cobertura report paths for Java.
As far as I know, the only option to import Cobertura reports for Java is to use sonar-cobertura and it seems to accept only a single report specified through sonar.cobertura.reportPath.