8bitjunkie
8bitjunkie

Reputation: 13245

Maven jacoco excludes does not work

 <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.0</version>
                <configuration>
                    <!-- remove haltOnFailure to purposely fail build once we recover coverage back to 70% -->
                    <haltOnFailure>false</haltOnFailure>
                    <rules>
                        <rule>
                            <element>CLASS</element>
                            <limits>
                                <limit>
                                    <counter>LINE</counter>
                                    <value>COVEREDRATIO</value>
                                    <minimum>0.70</minimum>
                                </limit>
                                <limit>
                                    <counter>BRANCH</counter>
                                    <value>COVEREDRATIO</value>
                                    <minimum>0.70</minimum>
                                </limit>
                            </limits>
                            <excludes>
                                <!-- exclude domain objects -->
                                <exclude>com/path/to/classes/**/*</exclude>                               
                            </excludes>
                        </rule>
                    </rules>
                </configuration>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>check</id>
                        <goals>
                            <goal>check</goal>
                            <goal>report</goal>
                        </goals>
                        <phase>verify</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>

Expected behaviour: The HTML report at target/site/jacoco/index.html does not contain a row for com/path/to/classes

Actual behaviour: The HTML report at target/site/jacoco/index.html includes a row for com/path/to/classes which causes the coverage to be reported as (in my case) 32%, proving that this package is being included and should not be.

enter image description here

I must be doing something wrong?

Upvotes: 3

Views: 12527

Answers (1)

Klaimmore
Klaimmore

Reputation: 690

You can completely exclude files from instrumentation/analysis/reports on configuration's excludes node

<configuration>
    <excludes>
        <exclude>com/path/to/classes/**/*</exclude>
    </excludes>
</configuration>

Excludes specified on the rule node ignore the classes excluded for that rule only

Upvotes: 6

Related Questions