DevOps Maven Multimodule project reporting incorrect code coverage

Dear team,

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
    Azure DevOps

  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI)
    Azure DevOps

  • Scanner command used when applicable (private details masked)
    Azure Pipeline YAML

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: REDACTED
    organization: REDACTED
    scannerMode: 'Other'
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    codeCoverageToolOption: 'JaCoCo'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.11'
    mavenVersionOption: 'Default'
    mavenAuthenticateFeed: false
    effectivePomSkip: false
    sonarQubeRunAnalysis: true
    isJacocoCoverageReportXML: true
    sqMavenPluginVersionChoice: 'latest'
- task: SonarCloudPublish@1
  inputs:
    pollingTimeoutSec: '300'
  • Languages of the repository
    Java/Maven

  • Only if the SonarCloud project is public, the URL

    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
    In a Maven multimodule project, SonarCloud is only reporting the last module as having code coverage, all other modules is reported as having 0% code coverage.

A similar issues appears to have been reported here Incomplete Jacoco code Coverage in multimodule maven project with no solution by member @DevonBritton

  • Steps to reproduce
    I created the following multimodule project
    <modules>
        <module>child1</module>
        <module>child2</module>
        <module>report</module>
    </modules>

Child 1 and Child 2 each has a class with a unit test. Report module is used to assist local developers to generate JaCoCo reports, but has the following properties

    <properties>
        <sonar.skip>true</sonar.skip>
    </properties>

SonarCloud only displays that Child 2 has 100% code coverage, and that Child 1 has 0% code coverage, even though the downloaded reports from Azure artifacts shows 100% code coverage for both modules.

Testing to ensure that it is not the Child 1 module that has any issues, I created the following module configuration

    <modules>
        <module>child2</module>
        <module>child3</module>
        <module>report</module>
    </modules>

SonarCloud now displays that Child 3 has 100% code coverage, and that Child 2 has 0% code coverage, even though the downloaded reports from Azure artifacts shows 100% code coverage for both modules.

I seems to appear that the reports send or getting processed by SonarCloud is only processing the last module for code coverage.

I can provide debugging logs from Azure DevOps as well as the minimal project in a DM to a SonarSource team member.

Regards

Hi @andrewbroekman,

Thanks for your detailed post.
I would be interested in your sample project to do some tests on my side, could you please send it to me through PM, with the logs produced during the analysis on Azure DevOps?

Claire

Good morning @Claire_Villard ,

I currently can’t see any way to send you a DM. I see from my account profile that I am at a basic trust level user. Can you please assist?

Best regards

Hi @andrewbroekman

I confirm JaCoCo configuration through Azure interferes with the manual JaCoCo configuration from pom.xml, and does not support both multi-modules and SonarCloud analysis.

To have the coverage on SonarCloud, here is what I suggest:

1/ Use that sample project to configure the aggregated report generation on your project

2/ Update the Azure Pipeline to do NOT use JaCoCo coverage from Azure, not SonarCloud analysis, and use the jacoco:report-aggregate and sonar:sonar Maven Goals instead to execute what you configured on the pom.xml.

Here is an example of Azure pipeline configured that way:

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: ***
    organization: ***
    scannerMode: 'Other'
    extraProperties: |
      sonar.projectName=***
      
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    goals: 'package jacoco:report-aggregate sonar:sonar'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.11'
    mavenVersionOption: 'Default'
    mavenAuthenticateFeed: false
    effectivePomSkip: false
    sonarQubeRunAnalysis: false

- task: SonarCloudPublish@1
  inputs:
    pollingTimeoutSec: '300'

Claire

1 Like