Search code examples
mavencode-coveragejacoco-maven-pluginmaven-site-plugin

how to integrate a test coverage reports in maven site for a multi modules project?


I would like to add a coverage report in my maven site website in the case of a multi-modules project.

I found how to have an aggregated coverage report in a module created just to for that. see .

But I did not find how to add a coverage report in my maven site website in the case of a multi modules project.

Does someone know to achieve that?

As requested, my parent pom is as follows. The comments in reporting tag are due to some tries to produce the report. I tried several configurations but no one generates the report.

Nothing is defined for coverage in child modules, except in coverage module that contains the generation of the aggregated coverage report.

The version of Maven is 3.8.6, the version of Java is open JDK 19, the version of the surfire plugin is 3.1.2. The version of Jacoco plugin is 0.8.10 .

<!-- parent and artifact defintions -->

<packaging>pom</packaging>

<properties>
    <!-- some properties -->
</properties>

<modules>
    <module>moduleA</module>
    <module>moduleB</module>
    <module>moduleC</module>
    <module>coverage</module>
</modules>

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

<distributionManagement>
    <site>
        <id>AAA site</id>
        <url><!-- a path --></url>
    </site>
</distributionManagement>
  
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.9</version>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>index</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <show>private</show>
            </configuration>
            <reportSets>
                <reportSet>
                    <id>javadoc</id>
                    <reports>
                        <report>javadoc</report>
                    </reports>
                </reportSet>
                <reportSet>
                    <id>aggregate</id>
                    <inherited>false</inherited>
                    <reports>
                        <report>aggregate</report>
                    </reports>
                </reportSet>
                <reportSet>
                    <id>test-javadoc</id>
                    <reports>
                        <report>test-javadoc</report>
                    </reports>
                </reportSet>
                <reportSet>
                    <id>test-aggregate</id>
                    <inherited>false</inherited>
                    <reports>
                        <report>test-aggregate</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.22.2</version>
            <configuration>
                <aggregate>true</aggregate>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <reportSets>
                <!-- <reportSet> -->
                <!-- <id>coverage</id> -->
                <!-- <configuration> -->
                <!-- <dataFileIncludes> -->
                <!-- <dataFileInclude>**/jacoco-unit.exec</dataFileInclude>  -->
                <!-- </dataFileIncludes> -->
                <!-- </configuration>                -->
                <!-- <reports> -->
                <!-- <report>report</report> -->
                <!-- </reports> -->
                <!-- </reportSet> -->
                <reportSet>
                    <id>coverage-aggregate</id>
                    <configuration>
                        <dataFileIncludes>
                            <dataFileInclude>**/target/jacoco-unit.exec</dataFileInclude>
                        </dataFileIncludes>
                    </configuration>
                    <inherited>false</inherited>
                    <reports>
                        <report>report-aggregate</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.1.2</version>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco.version}</version>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

Sincerely,


Solution

  • In fact it seems that's not supported. see here