Exclude classes of jar files from jacoco coverage report

人盡茶涼 提交于 2020-02-03 06:39:00

问题


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.


回答1:


I found the answer of it

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

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



来源:https://stackoverflow.com/questions/30727952/exclude-classes-of-jar-files-from-jacoco-coverage-report

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!