【问题标题】:Exclude classes of jar files from jacoco coverage report从 jacoco 覆盖率报告中排除 jar 文件类
【发布时间】:2015-08-24 00:42:43
【问题描述】:

Jacoco 代码覆盖率报告还包括我使用以下 maven 依赖项添加的“系统路径 jar”中的类

<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>

我试图从 jacoco 插件中排除这个 jar 的文件,如下所示:

            <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>

但排除不起作用。它仍然显示 jar 中包含的文件的覆盖率报告。 如图所示,org.apacke.org.clobus. 包中的文件不应出现在覆盖率报告中。

【问题讨论】:

  • 我认为排除模式只支持通配符的一些变体。例如。从前面:/**Test 或最后:org/apache/* - 我认为您的模式应该只是“org/apache/**/*”。另一种方法是使用包含并仅包含您自己的包,因为这可能是一个更短的列表。

标签: java maven jacoco


【解决方案1】:

我找到了答案

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

上述排除排除了我的 jar 文件中具有system 范围的类。

【讨论】:

  • 系统范围的文件结构似乎是基于它在 maven 构建中的放置方式,而不是它作为包目录的分解方式。
猜你喜欢
  • 2019-04-10
  • 1970-01-01
  • 2018-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-09
  • 1970-01-01
相关资源
最近更新 更多