diff-coverage-maven-plugin
diff-coverage-maven-plugin copied to clipboard
diff coverage for each submodule and aggregate report module
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>
Hi @eamon-t-2023
Could you please clarify
the problem is that diff coverage for each sub module may include data from other sub modules.
What do you mean may include data from other sub modules
?
@SurpSG Hi, thank you for your reply. that means the diff report of the moduleB including both the diff data of moduleA and moduleB.
this depends on the order of package the sub modules.
e.g.
if module A then module B, then diff report of moduleA just contains diff data of moduleA, but module B contains data from module A and module B.
if module B then module B, then diff report of moduleB just contains diff data of moduleB, but moduleA contains data from module A and module B.
@eamon-t-2023
Suppose B
depends on A
.
- When you trigger diff report generation on module
A
then expected reports is generated only forA
. - When trigger diff report generation on
B
then you get diff report that contains code from both modules.
And for the second case you want to see diff report only for the code from B
, correct?
@SurpSG let me do more investigation and update later
@SurpSG Hi, i added a test project https://github.com/tangyiming/diff-multiple-module-test , you can generate the diff reports in the dev branch by package the project.
you can see that the common module is not import by any other modules, but the diff report of this module contains all the data of the whole repo. this not meet our expectation.
the service module is a dependency of web module. so the diff report of web module contains data from service and self module.that's expected. and the web module only contains data of self data. also as expected.
and the diff report of aggregate-reports module is as expected.
Hi @eamon-t-2023
First of all, thank you for the example. It helped a lot to understand the root cause. The plugin was not designed to apply to each module, that's why we observe such strange behaviour.
For now you can configure the plugin's inputs manually to make it works as expected:
- configure
.exec
files. - configure classes files.
<!-- Optional. Exec files include pattern. By default 'build/jacoco.exec' file is used -->
<dataFileIncludes>**/custom/exec/location/*.exec</dataFileIncludes>
<!-- Optional. Exec files exclude pattern -->
<dataFileExcludes>**/custom/**/exclude/*.exec</dataFileExcludes>
<!-- Optional. Ant patterns by which we include classes for coverage report. -->
<includes>
<include>**/package/**</include>
<include>**/ClassNamePrefix*</include>
</includes>
<!-- Optional. Ant patterns by which we exclude classes from coverage report. -->
<excludes>
<exclude>**/exclude/**/ClassName.class</exclude>
</excludes>
I'll fix your case but it will take some time.
@SurpSG Sounds great LOL, wait for your next milestone 😃 Thank you so much
@eamon-t-2023 try my branch if you want per module https://github.com/rrourke/diff-coverage-maven-plugin/tree/subModuleFix
thanks ~ it works