Jacoco 索引 HTML 未显示所有模块

Jacoco index HTML doesn't show all modules

我有两个模块 maven 项目,当 运行 在本地时,我在 index.html 文件中看不到它们。

但我可以在目标文件夹 (\target\coverage-reports\jacoco) 下看到两个模块包。

下面是我的主POM。

   <profile>
        <id>coverage</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <properties>
            <run.profiles>test</run.profiles>
            <skipTests>false</skipTests>
            <checkstyle.skip>true</checkstyle.skip>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <argLine>${argLine}</argLine>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <configuration>
                        <destFile>${user.dir}/target/jacoco/${project.artifactId}.exec</destFile>
                        <excludes>
                            <exclude>**/*App*</exclude>
                            <exclude>**/test/**/*</exclude>
                            <exclude>**/it/**/*</exclude>
                            <exclude>**/*Config*</exclude>
                            <exclude>**/configuration/*</exclude>
                        </excludes>
                    </configuration>
                    <executions>
                        <execution>
                            <id>agent-for-ut</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>jacoco-site</id>
                            <phase>package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${user.dir}/target/jacoco/${project.artifactId}.exec</dataFile>
                                <outputDirectory>${user.dir}/target/coverage-reports/jacoco</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

我在单独的 POM 中进行了 jacoco 合并

<artifactId>jacoco-merge</artifactId>
<name>jacoco-m

erge</name>
    <packaging>pom</packaging>

    <profiles>
        <profile>
            <id>coverage</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                            <!-- merge separate coverage files into single coverage file -->
                            <execution>
                                <id>merge-results</id>
                                <goals>
                                    <goal>merge</goal>
                                </goals>
                                <configuration>
                                    <!-- This where the jenkins jacoco plugin expects the merged result -->
                                    <destFile>${user.dir}/target/jacoco.exec</destFile>
                                    <fileSets>
                                        <fileSet>
                                            <!-- This is where the individual builds put results -->
                                            <directory>${user.dir}/target/jacoco</directory>
                                            <includes>
                                                <include>*.exec</include>
                                            </includes>
                                        </fileSet>
                                    </fileSets>
                                </configuration>
                                <phase>test</phase>
                            </execution>

解决了问题,

由于我使用相同的共享位置来放置生成的报告,它会用最新的报告覆盖之前的报告。 因为正在使用模块特定数据文件生成报告,然后在最后生成报告。

所以在模块中存储报告解决了这个问题。

更改输出目录的下面一行

<outputDirectory>${user.dir}/${project.artifactId}/target/coverage-reports/jacoco</outputDirectory>