Java 在 jacoco 覆盖率报告中排除文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31383380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exclude folder in jacoco coverage report
提问by troger19
In my java project I have generated classes which are inside the same package folderas 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)
在我的 java 项目中,我生成了与其他类位于同一包文件夹中的类。我想配置 jacoco maven 插件以排除那些生成的类,并且只使用 main/src/java 文件夹中的类(不是 src/main/java-generated)
Project structure:
src/main/java/com/company/john/Good.java <---- this include
src/main/java-generated/com/company/john/AutoGeneratedClass.java <---- this exclude
项目结构:
src/main/java/com/company/john/Good.java <---- 这包括
src/main/java-generated/com/company/john/AutoGeneratedClass.java <---- 这个排除
<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>
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?
我知道,第一个选项是将前缀附加到生成的类 fi _ 并将其用于过滤,但我想知道是否还有另一个选项。如何指定源项目文件夹 (src/main/java) 从而排除所有其他文件夹?插件是否仅基于包名?
采纳答案by Dams
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 需要编译的类,因此您不能对源进行过滤。
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/.
您可以通过设置排除路径来排除 Jacoco 报告中的类,但值应该是编译类相对于目录 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.
最好的解决方案是在特定的包中生成类。但也许你不能。
回答by Vero J
Simply doing the below solved my problem of ignoring a package rather than the files.
只需执行以下操作即可解决我忽略包而不是文件的问题。
<configuration>
<excludes>
<exclude>**/basepkg/subpkg1/subpkg2/*</exclude>
</excludes>
</configuration>