在jacoco coverage报告中排除文件夹 [英] Exclude folder in jacoco coverage report

查看:744
本文介绍了在jacoco coverage报告中排除文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的java项目中,我生成了与其他类一样在相同包文件夹内的类。我想配置jacoco maven插件来排除那些生成的类,只使用main / src / java文件夹中的类(不是src / main / java生成的)

In my java project I have generated classes which are inside the same package folder as the other classes. I would like to configure jacoco maven plugin to exclude those generated classes and only use classes in the main/src/java folder (not src/main/java-generated)

项目结构:

src / main / java / com / company / john / Good.java< ----这包括

src / main / java-generated / com / company / john / AutoGeneratedClass.java< ---- this exclude

Project structure:
src/main/java/com/company/john/Good.java <---- this include
src/main/java-generated/com/company/john/AutoGeneratedClass.java <---- this exclude

<plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.5.201505241946</version>
            <configuration>
                <includes>
                </includes>
                <excludes>
                    <exclude>**/*Dto.*</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-check</id>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

我知道,1个选项是将前缀附加到生成的类f.i. _并使用它进行过滤,但我想知道是否还有其他选项。如何指定源项目文件夹(src / main / java),从而排除所有其他文件夹?该插件是否仅基于包名?

I know, that 1 option is to append the prefix to the generated class, f.i. _ and use this for filtering, but I am wondering if there is another option. How to specify the source project folder (src/main/java) and thus exclude all other folders? Is the plugin based only on package names?

推荐答案

我认为这是不可能的,因为您的编译类位于同一目录中目标。并且Jacoco需要编译的类,因此您无法对源进行过滤。

I think that is not possible because your compiled classes are in the same directory in target. And Jacoco needs the compiled classes and therefore you can not make a filter on sources.

您可以通过设置排除路径来排除Jacoco报告中的类,但值应该是编译类相对于目录target / classes /的路径。

You can exclude classes in the Jacoco report by setting an exclude path but the values should be the path of compiled classes relative to the directory target/classes/.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/*.class</exclude>
        </excludes>
    </configuration>
</plugin>

最佳解决方案是在特定包中生成类。但也许你不能。

The best solution would be to generate the classes in a specific package. But maybe you can't.

这篇关于在jacoco coverage报告中排除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆