How to ignore inner/nested classes with JaCoCo?
Asked Answered
H

2

20

I'm trying to ignore some generated classes, and the classes get ignored fine. But if those classes have inner classes, those classes still get included, despite the parent class being excluded. This is my configuration:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.9</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <excludes>
                    <exclude>**/*DB.*</exclude>
                    <exclude>**/*DTO.*</exclude>
                </excludes>
            </configuration>
        </execution>
    </executions>
</plugin>

Attempting to use the standard Java name convention of ParentClass.NestedClass by excluding **/*DB.*.* did not help.

Halla answered 22/8, 2017 at 9:56 Comment(0)
H
64

After some searching, I found the answer myself. As it wasn't easily googleable, I'm putting it here for posterity's sake:

The syntax mirrors that of the compiled Java naming convention:

<configuration>
    <excludes>
        <exclude>**/*DB.*</exclude>
        <exclude>**/*DB$*.*</exclude>
        <exclude>**/*DTO.*</exclude>
        <exclude>**/*DTO$*.*</exclude>
    </excludes>
</configuration>
Halla answered 22/8, 2017 at 13:4 Comment(2)
How come this hasn't got like 200+ upvotes ? Thanks TorqueCindiecindra
Thanks @Halla for this auto-answer, it also works for me.Miramontes
D
0

For a single class, something like this works

<exclude>.../[class name]*</exclude>
Dilate answered 1/8, 2022 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.