0

I am trying to use the jacoco exclude filter to filter out Controllers and DTO classes from coverage report. All controllers have the file format: *Controller.java and all dto files *Dto.java so I want to exculde on the basis of that.

This is what I have in pom.xml:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.12</version>
    <configuration>
        <excludes>
            <exclude>**/config/*</exclude>
            <exclude>com/example/mw/**/*Controller.java</exclude>
            <exclude>com/example/mw/**/*Dto.java</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>install</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>jacoco-check</id>
            <phase>install</phase>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
                <target>
                    <propertyfile file="lombok.config">
                        <entry key="config.stopBubbling" value="true"/>
                        <entry key="lombok.addLombokGeneratedAnnotation" value="true"/>
                    </propertyfile>
                </target>
                <rules>
                    <rule>
                        <element>BUNDLE</element>
                        <limits>
                            <limit>
                                <counter>LINE</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.61</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

I have tried various combinations trying complete wildcard configurations but nothing works these classes still show up in coverage report. Only manually adding @Generated annotation works but I want to do it so that all controllers and dtos get handled automatically.

Please let me know what am I doing wrong. I have tried all online solutions. I am using java 17 with spring boot 3.x.

P.S. I have tried clean build, rebuild many times to no avail only Generated makes difference. I tried to add annotation of Generated on compile to every class but it only adds that to constructor not the entire class so not useful either.

1
  • 2
    JaCoCo works on classes and not on sources. Try this exclusion: com/example/mw/**/*Dto.class
    – Mar-Z
    Commented Apr 5 at 6:32

0