7

Jacoco code coverage report is also including classes from "system path jar" that I have added using below maven dependency

<dependency>
            <groupId>axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.2.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/axis-1.2.1.jar</systemPath>
        </dependency>

I tried to exclude the files of this jar from jacoco plugin like this :

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.2.201409121644</version>
                <configuration>
                    <excludes>
                        <exclude>**/org/apache/**/*</exclude>
                        <exclude>**/org/globus/**/*</exclude>
                    </excludes>
                </configuration>

                <executions>
                    <execution>
                        <id>pre-unit-test</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/jacoco.exec</destFile>
                            <!-- Sets the name of the property containing the settings for JaCoCo 
                                runtime agent. -->
                            <propertyName>surefireArgLine</propertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile>
                            <!-- Sets the output directory for the code coverage report. -->
                            <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

But the exclusion is not working. It is still showing the coverage report for the files contained in jar. As it is shown in image, the files in org.apacke. and org.clobus. package should not be there in the coverage report.

enter image description here

RaT
  • 1,134
  • 3
  • 12
  • 28
  • 1
    I think the exclude pattern only supports some variations of wildcards. E.g. either from the front: */**Test* or at the end: org/apache/* - I think your pattern should only be "org/apache/**/*". Another way would be to work with includes and only include your own packages, since that will probably be a much shorter list. – wemu Jun 09 '15 at 11:29

1 Answers1

7

I found the answer of it

 <exclude>**/lib/*</exclude>

The above exclusion exclude the classes from my jar file with system scope.

Patrick
  • 33,984
  • 10
  • 106
  • 126
RaT
  • 1,134
  • 3
  • 12
  • 28
  • It seems that system scope's file structure is based on how it is put in the maven build, not how it is exploded as package dirs. – Patrick Feb 28 '17 at 08:13
  • How to exclude a jar from Jacoco JavaAgent or it can only takes classes(need to extract jar?) ? – Mehul Parmar Jul 06 '23 at 06:57