A_G
A_G

Reputation: 2370

Exclude files in Jacoco Coverage Report

I have been trying to remove certain files from the generated coverage report. I tried below things:

<plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.1</version>
            <executions>
                <execution>
                    <id>report-aggregate</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>report-aggregate</goal>
                    </goals>
                    <configuration>
                        <excludes>
                            <exclude>**/com/abc/def/**</exclude>
                        </excludes>
                    </configuration>
                </execution>
                <execution>
                    <id>check</id>
                    <goals>
                        <goal>check</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <rule >
                                <element>BUNDLE</element>
                                    <limits>
                                        <limit >
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.50</minimum>
                                        </limit>
                                    </limits>
                            </rule>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Modified code:

<plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.9</version>
            <configuration>
                <excludes>
                    <exclude>**/com/abc/def/**</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>report-aggregate</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>report-aggregate</goal>
                    </goals>
                </execution>
                <execution>
                    <id>check</id>
                    <goals>
                        <goal>check</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <rule >
                                <element>BUNDLE</element>
                                    <limits>
                                        <limit >
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.50</minimum>
                                        </limit>
                                    </limits>
                            </rule>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Also tried,

<configuration>
                        <rules>
                            <rule >
                                <element>BUNDLE</element>
                                    <limits>
                                        <limit >
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.50</minimum>
                                        </limit>
                                    </limits>
                                <excludes>
                                    <exclude>com.abc.def.className</exclude>
                                </excludes>
                            </rule>
                        </rules>
                    </configuration>

Some of the many links I referred while trying to reach the solution:

Maven Jacoco Configuration - Exclude classes/packages from report not working

Jacoco how to correctly exclude package

How to add more Jacoco exclusions in a child project?

http://tdongsi.github.io/blog/2017/09/23/jacoco-in-maven-project/

But every time I generate the report, the files still show up in the given module.

Upvotes: 5

Views: 6601

Answers (1)

Ash
Ash

Reputation: 268

After also being stuck at this for hours, here's what I did:

<configuration>
     <excludes>
          <exclude>com/package/name/FileName*</exclude>
     </excludes>
</configuration>

Adding * after filename was the critical part for me. I had tried putting FileName.java several times but it would still include it util I added *

Upvotes: 3

Related Questions