Coverage reports are empty in Maven multi-module project

Hi!

We are using Jacoco’s aggregated report for a Maven multi-module project as described in Java test coverage | SonarQube Server Documentation, also including the “…/” fix for the sonar.coverage.jacoco.xmlReportPaths property that we found in other topics in this community.

The root pom.xml contains these:

  <build>
    <pluginManagement>
       <plugins>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <version>3.13.0</version>
           <configuration>
             <source>8</source>
             <target>8</target>
           </configuration>
         </plugin>
         <plugin>
           <groupId>org.sonarsource.scanner.maven</groupId>
           <artifactId>sonar-maven-plugin</artifactId>
           <version>${sonar.plugin.version}</version>
         </plugin>
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
           <version>${jacoco.plugin.version}</version>
         </plugin>
       </plugins>
    </pluginManagement>
    <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>

and this:

  <properties>
    <jacoco.plugin.version>0.8.12</jacoco.plugin.version>
    <sonar.plugin.version>5.0.0.4389</sonar.plugin.version>
    
    <sonar.host.url>https://sonarcloud.io</sonar.host.url>
    <sonar.organization>myproject-dev</sonar.organization>
    <sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../aggregate-coverage-report/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
  </properties>

And the module with the report contains this:

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

Using mvn clean verify I can confirm that the report is generated just fine and the coverage is about 56%.

When I ran mvn sonar:sonar, I can see that the report is being picked up:

sonar_scanner.log (44.1 KB)

However, in sonarcloud.io, I see that the coverage is 0.0%:

What am I missing?

Thank you in advance!

It turns out that the problem was related with this old plugin I had in the <pluginManagement> section:

        <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-jar-plugin</artifactId>
           <version>2.4</version>
         </plugin>

Once I removed that everything started to show up like a charm in sonarcloud.io.

I can’t explain it but I thought I should share the “fix” to the community because I can see it affects at least several people.

Wow, that would have been hard to figure out. Thanks for sharing!

Have you checked to see if there’s a difference in the coverage report generated when you update the maven-jar-plugin?

No, I haven’t but I assume it will look the same, since I’m using the latest maven version and it is already pulling down the latest version of the plugin.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.