如何在多模块Maven项目中集成测试覆盖率报告至Maven Site
多模块Maven项目中集成Jacoco聚合覆盖率报告到Maven Site
我希望在多模块Maven项目的Maven Site网站中添加测试覆盖率报告。目前已经掌握通过专门创建的coverage模块生成聚合覆盖率报告的方法,但还没找到将该报告集成至Maven Site的实现方式,请问有人知道怎么操作吗?
环境信息
- Maven 3.8.6
- Open JDK 19
- Surefire插件 3.1.2
- Jacoco插件 0.8.10
配置说明
除了负责生成聚合覆盖率报告的coverage模块外,其他子模块未配置任何覆盖率相关内容。以下是我的父pom.xml配置,reporting标签中的注释是之前尝试生成报告时留下的,试过多种配置都没能成功生成报告:
<!-- 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>
内容的提问来源于stack exchange,提问作者nizery
相关产品推荐
相关产品推荐

