Search code examples
maven-3sonarqube-scanmaven-surefire-pluginjacoco-maven-plugin

Jacoco index HTML doesn't show all modules


I have two modules maven project, when run locally I can't see both in index.html file.

But I can see both modules packages under target folder (\target\coverage-reports\jacoco).

Below is my main 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>

I do a jacoco merge in separate POM

<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>

Solution

  • Figured out the issue,

    Since I use the same shared location to place the generated reports, it will override the previous one with latest one. Because reports are being generated using module specific data file and then generate the report at the end.

    So storing report inside the module fix the issue.

    Change the below line of the output directory

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