2
 <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?

8bitjunkie
  • 12,793
  • 9
  • 57
  • 70

1 Answers1

6

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

Klaimmore
  • 680
  • 1
  • 6
  • 16
  • 2
    Thanks - did not notice that I had erronously included my `` block within my `` block instead of under my `` block. Thanks for the pointer (although my config needed to be in an `` line nested inside the `` parent in order to work). – 8bitjunkie Mar 21 '18 at 15:20