Test coverage report from scoverage-maven-plugin not publishing to SonarQube

SonarQube 9.4.0.54424
SonarScanner 5.8.0

I’m trying to generate a code coverage report from a Maven, Scala project.
It’s a multi-module project and I use scoverage-maven-plugin v1.4.11 to generate the aggregated coverage reports. The project is built in Java8.
I have the prepare step setup in devops as

  - task: SonarQubePrepare@5
    inputs:
      SonarQube: 'SonarCube_Prod'
      scannerMode: 'Other'
      extraProperties: |
        sonar.projectKey=xx
        sonar.projectName=xx
        sonar.core.codeCoveragePlugin=scoverage
        sonar.scala.coverage.reportPaths=$(Build.SourcesDirectory)/xx/target/cobertura.xml

I build the project, then switch the environment to Java11 for SonarQube to work.

To generate the report I use

  • task: Maven@3 with goals: ‘scoverage:report-only’

Then to run the analysis I use

  • task: Maven@3 with sonarQubeRunAnalysis: true

When I investigate the SonarQube Analysis logs I see

[INFO] Sensor Scoverage sensor for Scala coverage [sonarscala]
[INFO] Importing /workspace/9/s/xx/target/cobertura.xml
[INFO] Sensor Scoverage sensor for Scala coverage [sonarscala] (done) | time=406ms

Which leads me to believe the coverage file has been found and uploaded
Finally I run SonarQubePublish@5

However the dashboard reflects 0% coverage.
If I publish the coverage file to Devops it correctly reflects the actual coverage.
How do I get my coverage correctly reflected in SonarQube?

Thanks,
Robert

Hey there.

Can you share a screenshot of what you do see in SonarQube?

Sure,

Hi,
Any update on this?

Thanks

Hey there.

It’s definitely strange that there are no other warnings/errors in the log – I would suggest two things:

  • Outside of Azure DevOps reporting coverage, have you verified that /workspace/9/s/xx/target/cobertura.xml contains coverage information (it’s not, for example, reporting 0s for all fies?)
  • Can you upload a snippet of your coverage file?

cobertura.txt (4.3 KB)
I’ve attached a snippet of the cobertura.xml file

Hello @Schuits
Thanks for providing all this information.
With the different tasks of the pipeline taking place in a different context, are the file paths matching from one task to the other?
I am asking because this has happened in the past with coverage information built using absolute paths that cannot be matched from one task to the other

Hi Dorian,

I’m pretty sure they are. I’ve taken the following bits from the logs

SonarQubePrepare
sonar.scala.coverage.reportPaths=/workspace/27/s/xx/xx/target/cobertura.xml

PublishCoverageResults (to devops)
##[debug]summaryFileLocation=/workspace/27/s/xx/xx/target/cobertura.xml

SonarQube Analysis
Importing /workspace/27/s/xx/xx/target/cobertura.xml

SonarQube Publish
##[debug]SONARQUBE_SCANNER_PARAMS={…“sonar.core.codeCoveragePlugin”:“scoverage”,“sonar.scala.coverage.reportPaths”:“/workspace/27/s/xx/xx/target/cobertura.xml”}

The “xx” are just the project folders and are identical.

FWIW I’ve attached the main pom file.

Regards,
Robert
pom.txt (2.9 KB)