[Coverage missing]On Sonarqube Coverage is not showing (Multimodule maven project)

Q: I have the following configuration in Multi-module AEM project. I am facing an issue with the code coverage report on SonarQube. I have test cases part of core modules that I want to cover. So I can see that module is appearing in Jenkins but code coverage is not showing up in SonarQube. Any help please?

SonarQube Version: Community Edition Version 8.2
I maven multi-module project. (AEM)
Base POM file

  • Child M1(all)
  • Child M2 (core) -> src/main, src/test (I want to cover all the test cases part of this directory)
  • Child M3 (it.tests) -> src/main

Base POM.xml file I have added the following configuration.

#Base pom file

    <aggregate.report.dir>target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.language>java</sonar.language>

# Under properties section I have mentions the sonar coverage path
   <properties>
        <sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
    </properties>

<pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>0.8.4</version>
        </plugin>
        <plugin>
          <groupId>org.sonarsource.scanner.maven</groupId>
          <artifactId>sonar-maven-plugin</artifactId>
          <version>3.7.0.1746</version>
        </plugin>
</pluginManagement>
# I have added the jacoco profile
<profiles>
  <profile>
      <id>coverage</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>prepare-agent</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

My M2 (Core) module is having all the test cases.


# Core pom file
# Under properties section I have mentions the sonar coverage path
   <properties>
        <sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
    </properties>

it.test module is having generated jacoco.xml file in target directory.
Pom file configuration in it.tests module.

  • I have added the execution goals.
  • I have added the Sonar coverage xml path
  • Also I have added the dependency of the core project in the same pom.xml file.
<properties>
        <junit.version>4.8.2</junit.version>
        <sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <executions>
                    <execution>
                        <id>report</id>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                        <phase>verify</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
 </build>

  • Jenkins configuration
  • SonarQube configuration
  • SonarQube Result

The command I am running from my mac terminal

mvn -X clean verify sonar:sonar \
  -Dsonar.projectKey=abc \
  -Dsonar.host.url=http://servername:9000 \
  -Dsonar.login=token

Also it says analysis successful. But still, code coverage is not showing up in SonarQube.

In Jenkins: I can see the jacoco report. (I am not sure this is correct or not)

#Also if I will go to it.tests/target/…/…/jacoco-aggregate/index.html and open the index.html then I will able to see this. (Please ignore the spell mistakes)

Hey there!

Thanks for reaching out to the community. I see you have an issue with coverage not appearing in SonarQube, and from the screenshot, it looks like the analyzer is able to find the coverage report file successfully. Coverage is pretty straightforward for SonarQube analyses. The analyzer simply finds the coverage report and imports the values, but there are a few things that can get in the way of that.

Here are a few things we should check initially:

  1. Check if any coverage exclusions are set, as mentioned in our documentation.
  2. Check the contents of the coverage report xml file for any inconsistencies.
    3.Check the ce logs to see if there were any issues processing that info on the SonarQube side.

Feel free to share any of that info here and we can keep working on it.

@Joshua_Martin : Thanks for the suggestion.

I have gone through the analysis. It is reading the report from it.tests module but from other modules it is skipping since other modules are not generating jacoco.xml report.

  • I have validated the jacoco.xml and it is valid.
  • I have added the sonar properties only in Jenkins
sonar.projectKey=abc
sonar.projectName=aem
sonar.projectVersion=1.0
sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco-aggregate/jacoco.xml
sonar.java.coveragePlugin=jacoco
# Project description
sonar.projectDescription=This is abc AEM project analysis.
  • Following is the debug log. Which is saying that jacoco reading the xml file.
[INFO] 16:43:11.618 Sensor SonarCSS Rules [cssfamily]
[INFO] 16:43:11.619 No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[INFO] 16:43:11.619 Sensor SonarCSS Rules [cssfamily] (done) | time=1ms
[INFO] 16:43:11.619 Sensor JaCoCo XML Report Importer [jacoco]
[DEBUG] 16:43:11.619 Reading report '/Users/user/projects/-project/AEM/it.tests/target/site/jacoco-aggregate/jacoco.xml'
[INFO] 16:43:11.621 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms
[INFO] 16:43:11.621 Sensor JavaXmlSensor [java]
[INFO] 16:43:11.621 1 source files to be analyzed
[DEBUG] 16:43:11.623 'pom.xml' generated metadata with charset 'UTF-8'

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for-SNAPSHOT:
[INFO] 
[INFO] base.............................................. SUCCESS [ 44.529 s]
[INFO] - Core ........................................ SUCCESS [  6.113 s]
[INFO] - Repository Structure Package ................ SUCCESS [  0.600 s]
[INFO] - UI apps ..................................... SUCCESS [  6.215 s]
[INFO] - UI content .................................. SUCCESS [  1.971 s]
[INFO] - All ......................................... SUCCESS [  1.124 s]
[INFO] - Integration Tests Bundles ................... SUCCESS [  1.638 s]
[INFO] - Integration Tests Launcher .................. SUCCESS [  0.772 s]
[INFO] dispatcher ......................................... SUCCESS [  0.394 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:05 min
[INFO] Finished at: 2020-04-15T16:43:30-07:00
[INFO] ------------------------------------------------------------------------

Does this configuration matter in generating the passing jacoco.xml file?

Also above configuration is running after sonar scanner.

I have gone through the following article and some other articles but no help :frowning:

https://community.sonarsource.com/t/coverage-test-data-importing-jacoco-coverage-report-in-xml-format/12151