Aggregated Coverage for Multi-Module Maven Project

Hi,
we are trying to gather aggregated coverage for our multi-module projects.
Our plugin configuration:

<plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <executions>
                        <execution>
                            <id>pre-unit-test</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>pre-integration-test</id>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                            <configuration>
                                <append>true</append>
                                <destFile>${project.build.directory}/jacoco.exec</destFile>
                                <propertyName>failsafeArgLine</propertyName>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-integration-test</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                        <!-- Goal check is bound to the verify phase -->
                        <execution>
                            <id>default-check</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <rule>
                                        <element>BUNDLE</element>
                                        <limits>
                                            <limit>
                                                <counter>BRANCH</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>${jacoco.coveredratio}</minimum>
                                            </limit>
                                        </limits>
                                    </rule>
                                </rules>
                            </configuration>
                        </execution>
                        <execution>
                            <id>report-aggregate</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report-aggregate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

Our SonarQube properties

<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

We do get the jacoco-aggregate folder generated. However SonarQube show the coverage as 0%.
If use the jacoco/jacoco.xml file, the coverage is shown.

I verified that the aggregated xml files have proper content and they do look fine for me.

Any idea or hints how I could get this working.

wanted to follow up on this.
Has anyone any experience how to gather aggregated coverage using jacoco and sonarqube?

Hi Timo,

You need to set in each module a relative path for sonar.coverage.jacoco.xmlReportPaths to the aggregated report using ../
e.g.:

<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../path_to_module_with_report/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>`

See § Multi-module builds of [Coverage & Test Data] Importing JaCoCo coverage report in XML format

1 Like