Skip to content

diff coverage for each submodule and aggregate report module  #43

@eamon-t-2023

Description

@eamon-t-2023

For now, I can generate the diff coverage for aggregate report module, but failed for each sub module. Any ideas about generate diff coverage for each sub modules and the aggregate report module at the same time when i compile the whole repo.

the problem is that diff coverage for each sub module may include data from other sub modules.

repo structure:

  • aggregate-reports
  • moduleA
  • moduleB

pom of aggregate-reports module:

<build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.10</version>
                <configuration>
                    <destFile>target/coverage-reports/custom-jacoco.exec</destFile>
                    <dataFile>target/coverage-reports/custom-jacoco.exec</dataFile>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report-aggregate</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                        <configuration>
                            <dataFileIncludes>target/coverage-reports/custom-jacoco.exec</dataFileIncludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.surpsg</groupId>
                <artifactId>diff-coverage-maven-plugin</artifactId>
                <version>0.3.2</version>
                <configuration>
                    <!-- Required. diff content source. only one of file, URL or Git is allowed -->
                    <diffSource>
                        <!-- path to diff file -->
                        <file>diff.txt</file>
                    </diffSource>
                    <!-- Optional. Exec files include pattern. By default 'build/jacoco.exec' file
                    is used -->
                    <dataFileIncludes>**/coverage-reports/custom-jacoco.exec</dataFileIncludes>
                </configuration>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>diffCoverage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

pom of sub module:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <skip>false</skip>
                    <testFailureIgnore>false</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>generate-surefire-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- 单元测试覆盖率插件 -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.10</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <destFile>${project.build.directory}/coverage-reports/custom-jacoco.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>target/coverage-reports/custom-jacoco.exec</dataFile>
                            <outputDirectory>target/site/jacoco</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule implementation="org.jacoco.maven.RuleConfiguration">
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit implementation="org.jacoco.report.check.Limit">
                                            <counter>COMPLEXITY</counter>
                                            <value>COVEREDRATIO</value>
                                            <!-- 0.01 means 1% -->
                                            <minimum>0.00</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.surpsg</groupId>
                <artifactId>diff-coverage-maven-plugin</artifactId>
                <version>0.3.2</version>
                <configuration>
                    <!-- Required. diff content source. only one of file, URL or Git is allowed -->
                    <diffSource>
                        <!-- path to diff file -->
                        <file>diff.txt</file>
                    </diffSource>
                    <!-- Optional. Exec files include pattern. By default 'build/jacoco.exec' file is used -->
                    <dataFileIncludes>target/coverage-reports/service-jacoco.exec</dataFileIncludes>
                </configuration>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>diffCoverage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions