0

There are lots of answered questions on SO, but I still can't get this to work. I have a multi module Maven project. I followed https://www.baeldung.com/maven-jacoco-multi-module-project to set up JaCoCo. I have a report-aggregate/target/site directory, and jacoco-aggregate/index.html shows 100% coverage.

When I run mvn install sonar:sonar I get a warning for each submodule

No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths='C:\Users\me\IdeaProjects\test\sub2/target/site/jacoco-aggregate/jacoco.xml'. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml

That is for sub2, sub1 and the main module, in that order, and with sonar.coverage.jacoco.xmlReportPaths set to ${project.basedir}/target/site/jacoco-aggregate/jacoco.xml. On http://mysonarqube:9000 it says "Coverage not computed".

When I change sonar.coverage.jacoco.xmlReportPaths to ${project.basedir}/report-aggregate/target/site/jacoco-aggregate/jacoco.xml I get the same warnings for sub2, sub1 and report-aggregate, because C:\Users\me\IdeaProjects\test\report-aggregate/report-aggregate/target/site/jacoco-aggregate/jacoco.xml can't be found.

The Maven output does say in both cases

Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.

mvn install sonar:sonar -X shows that the report xml is found, and at a late point

[DEBUG] 'Generic Coverage Report' skipped because of missing configuration requirements.
Accessed configuration:
- sonar.coverageReportPaths: <empty>

I tried setting sonar.coverageReportPaths to the same value as sonar.coverage.jacoco.xmlReportPaths, but it only led to an exception because the xml format is different.

These lines are also always in the output:

[WARNING] Missing blame information for the following files:
[WARNING] * pom.xml
[WARNING] This may lead to missing/broken features in SonarQube

The documentation says it's related to fancy git states. For this test project I'm on the master branch with an initial commit only. Edit: pom.xml was simply not committed.

How can I have my project with the report-aggregate analysed with SonarQube, including the code coverage? Thanks in advance.

This is my pom.xml:

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>me.test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>sub1</module>
        <module>sub2</module>
        <module>report-aggregate</module>
    </modules>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <sonar.plugin.version>5.0.0.4389</sonar.plugin.version>
        <sonar.projectKey>test</sonar.projectKey>
        <sonar.projectName>test</sonar.projectName>
        <sonar.qualitygate.wait>true</sonar.qualitygate.wait>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.host.url>http://mysonarqube:9000</sonar.host.url>
        <sonar.token>***</sonar.token>
        <sonar.coverage.jacoco.xmlReportPaths>
            ${project.basedir}/target/site/jacoco-aggregate/jacoco.xml
        </sonar.coverage.jacoco.xmlReportPaths>
        <sonar.language>java</sonar.language>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter</artifactId>
                <version>5.11.3</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.11</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>5.0.0.4389</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

And report-aggregate/pom.xml:

<?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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.unisys.ch.nabodat</groupId>
        <artifactId>test</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>report-aggregate</artifactId>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.unisys.ch.nabodat</groupId>
            <artifactId>sub1</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.unisys.ch.nabodat</groupId>
            <artifactId>sub2</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                        <configuration>
                            <dataFileIncludes>
                                <dataFileInclude>**/jacoco.exec</dataFileInclude>
                            </dataFileIncludes>
                            <outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
1
  • Got my project analysed one module at a time including code coverage in SonarQube. That's great. Honestly I don't know what the difference is with an additional report-aggregate module. Maybe someone can shed some light on that. Commented Feb 20 at 12:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.