Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude folder in jacoco coverage report

Tags:

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)

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> 

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?

like image 830
troger19 Avatar asked Jul 13 '15 12:07

troger19


People also ask

How do you exclude classes in JaCoCo code coverage?

Starting from JaCoCo 0.8. 2, we can exclude classes and methods by annotating them with a custom annotation with the following properties: The name of the annotation should include Generated. The retention policy of annotation should be runtime or class.

How do I exclude a package from code coverage?

Edit Configurations > Select Code Coverage tab > then adding the package or class I want to be excluded or include only in the code coverage report.

How do I skip JaCoCo coverage?

The check goal has a skip parameter: eclemma.org/jacoco/trunk/doc/check-mojo.html#skip - so it would be -Djacoco. skip=true - it seems this skips all of the jacoco goals. If you don't want that maybe temporarily move the check goal into a profile you can activate when back on track?

How do you exclude model classes from code coverage?

The easiest way to exclude code from code coverage analysis is to use ExcludeFromCodeCoverage attribute. This attribute tells tooling that class or some of its members are not planned to be covered with tests. EditFormModel class shown above can be left out from code coverage by simply adding the attribute.


2 Answers

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.

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.

like image 50
Dams Avatar answered Sep 21 '22 03:09

Dams


Simply doing the below solved my problem of ignoring a package rather than the files.

<configuration>     <excludes>         <exclude>**/basepkg/subpkg1/subpkg2/*</exclude>     </excludes> </configuration> 
like image 31
Vero J Avatar answered Sep 17 '22 03:09

Vero J