Exclude folder in jacoco coverage report
Asked Answered
W

3

27

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?

Wafture answered 13/7, 2015 at 12:25 Comment(0)
H
28

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.

Heavenly answered 13/7, 2015 at 15:14 Comment(3)
Thanks for the reply dams and for pointing to the target/classes/ directoryWafture
why do you need 2 * characters before the first forward slash?Biskra
@alex, the two * are used to look in every folder preceding *.classPiecework
S
17

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

<configuration>
    <excludes>
        <exclude>**/basepkg/subpkg1/subpkg2/*</exclude>
    </excludes>
</configuration>
Shaky answered 12/9, 2016 at 8:20 Comment(0)
H
4

This is how I excluded any class generated by Jooq

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco-version}</version>
    <configuration>
      <excludes>
        <exclude>**/jooq/**/*.class</exclude>
      </excludes>
    </configuration>
</plugin>
Hispid answered 21/3, 2021 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.