Code Coverage not processed by SQ

Maven multimodule project based on Java 17

  • SonarQube Server (Community Build - v25.5.0.107428)
  • sonar plugin version: 3.11.0.3922
  • jacoco plugin version: 0.8.11
  • SonarQube deployed: Docker
  • in root pom.xml is set: <sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/server-jacoco-report/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
  • in report module is set:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent>
        <artifactId>business-server</artifactId>
        <groupId>com.company.server</groupId>
        <version>2.1.19-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>server-jacoco-report</artifactId>
    <version>2.1.19-SNAPSHOT</version>
    <packaging>pom</packaging>

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

    <!-- Needed for getting reports from given modules -->
    <dependencies>
        analyzed modules
    </dependencies>

</project>

In each analyzed module pom.xml is set

 <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <phase>initialize</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

The sonar/jacoco analysis is processed successfully but code coverage in SQ server is always 0%, expected ca 11% as in ./server-jacoco-report/target/site/jacoco-aggregate/index.html

Hi,

Welcome to the community!

Is this the version of the SonarScanner for Maven that you’re using? The current version is 5.1. It probably won’t have a bearing on your issue, but a good first step would be to upgrade.

Regarding your coverage, can you provide your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

Hi Ann,
Thank you for your fast answer. I upgraded Maven sonar scanner plugin to version 5.1.0.4751. But after that is the state same.

My analysis command is

mvn clean verify sonar:sonar -Dsonar.projectKey=%SONAR_PROJECT_KEY% -Dsonar.host.url=%SONAR_HOST_URL% -Dsonar.token=%SONAR_TOKEN%

I tried to split to these commands too
mvn clean verify -X
and
mvn sonar:sonar -Dsonar.projectKey=%SONAR_PROJECT_KEY% -Dsonar.host.url=%SONAR_HOST_URL% -Dsonar.token=%SONAR_TOKEN% -X
with output to files below
sonar-scanner.log
mvn-verify.log (675.7 KB)

Thank you
Marek

Hi Marek,

It looks like you’ve set this up per the docs for adding coverage to a multi-module Maven project. The only significant variation I see is this:

Versus the docs’

Explicitly, the difference I see is yours

${project.basedir}/server-jacoco-report/target/site/jacoco-aggregate/jacoco.xml`

Docs’

${maven.multiModuleProjectDirectory}/report-aggregate/target/site/jacoco-aggregate/jacoco.xml

I’m not certain this will work since the log you provided acts like the property was never set:

But can you drop that leading ${project.basedir} on your path and try again?

 
Thx,
Ann

Hi Ann,
I changed property mentioned above to
<sonar.coverage.jacoco.xmlReportPaths>${maven.multiModuleProjectDirectory}/server-jacoco-report/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
and now is the coverage displayed correctly on SQ server project page.

Thank you very much!
Marek

1 Like

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