如何在多模块项目的 Maven 站点中集成测试覆盖率报告?

问题描述 投票:0回答:1

对于多模块项目,我想在我的 Maven 网站中添加覆盖率报告。

我找到了如何在为此创建的模块中生成聚合覆盖率报告。 .

但是我没有找到如何在多模块项目的情况下在我的 Maven 网站中添加覆盖率报告。

有人知道如何实现这一目标吗?

根据要求,我的父pom如下。报告标签中的注释是由于一些生成报告的尝试而产生的。我尝试了几种配置,但没有人生成报告。

除了包含生成聚合覆盖率报告的覆盖率模块外,子模块中没有为覆盖率定义任何内容。

Maven的版本是3.8.6,Java的版本是open JDK 19,surfire插件的版本是3.1.2。 Jacoco插件的版本是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>

真诚的,

maven code-coverage jacoco-maven-plugin maven-site-plugin
1个回答
0
投票

事实上似乎不支持。参见这里

© www.soinside.com 2019 - 2024. All rights reserved.