简体   繁体   中英

How to ignore inner/nested classes with JaCoCo?

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.

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>

For a single class, something like this works

<exclude>.../[class name]*</exclude>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM