2

I am trying to exclude certain package and classes from Jacoco coverage since they are deprecated. I tried adding exclude in Jacoco plugin as below but when I look at the Jenkins report on Jenkins, I see all those classes as well not covered and the number of lines including them.

Here is my dir structure for the things I want to ignore.

com/dir1/dir2/dir3/dir4/dir5/XYZScreeningTask.java
com/dir1/dir2/dir3/dir4/dir6/dir7/XYZScreeningData.java
com/dir1/dir2/dir3/dir4/dir8/xyzscreening/BaseXYZFileProcessor.java
com/dir1/dir2/dir3/dir4/dir8/xyzscreening/XYZScreeningFileProcessor.java
com/dir1/dir2/dir3/dir4/dir8/abccmcactivity/AbcCMSActivityProcessor.java

Here is the pattern added below under plugins

<excludes>
    <exclude>com/dir1/dir2/dir3/dir4/**/*xyz*/**</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/**/*XYZ*.*</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/**/*abc*/**</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/**/*Abc*.*</exclude>
</excludes>

And here is the plugin info where exclusions has been added.

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <configuration>
                    <excludes>
                        <exclude>com/dir1/dir2/dir3/dir4/**/*xyz*/**</exclude>
                        <exclude>com/dir1/dir2/dir3/dir4/**/*XYZ*.*</exclude>
                        <exclude>com/dir1/dir2/dir3/dir4/**/*abc*/**</exclude>
                        <exclude>com/dir1/dir2/dir3/dir4/**/*Abc*.*</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>instrument</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>restore</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>restore-instrumented-classes</goal>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>pre-unit-test</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>post-unit-test</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
Atihska
  • 4,803
  • 10
  • 56
  • 98

1 Answers1

2

As the Jacoco documentation for excludes says

A list of class files to exclude from the report. May use wildcard characters (* and ?). When not specified nothing will be excluded.

You will need to specify classpath of the compiled classes. I fail to see a pattern in the files and packages that you want to exclude so if you want to exclude specific classes.

<excludes>
    <exclude>com/dir1/dir2/dir3/dir4/dir6/dir7/XYZScreeningData.class</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/dir8/xyzscreening/BaseXYZFileProcessor.class</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/dir8/xyzscreening/XYZScreeningFileProcessor.class</exclude>
    <exclude>com/dir1/dir2/dir3/dir4/dir8/abccmcactivity/AbcCMSActivityProcessor.class</exclude>
</excludes>

Nevertheless, We can exclude the complete package by something like follow,

<exclude>com/dir1/**/*</exclude>

The more about wildcards can be found From here and here. Which says.

* matches zero or more characters
** matches zero or more directories
? matches a single character
  • I have included the pattern in the second code base under plugins. The first code was just referring to the dir structure that I have. Now, added it separately as well. – Atihska Aug 02 '21 at 17:20