Maven Jacoco Configuration - Exclude classes/packages from report not working

resilva87

I have a maven multi-module project and I'm using jacoco-maven for code coverage reports. Some classes should not be reported, as they're Spring configuration and I'm not interested in them.

I have declared the maven-jacoco plugin as follow:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
    <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
    <exclude>some.package.*</exclude>
    <exclude>**/*Config.*</exclude>
    <exclude>**/*Dev.*</exclude>
    <exclude>some/package/SomeClass.java</exclude>
</configuration>
<executions>
    <execution>
        <goals>
            <goal>prepare-agent</goal>
        </goals>
    </execution>
    <execution>
        <id>report</id>
        <phase>prepare-package</phase>
        <goals>
            <goal>report</goal>
        </goals>
    </execution>
    <execution>
        <id>post-unit-test</id>
        <phase>test</phase>
        <goals>
            <goal>report</goal>
        </goals>
    </execution>
</executions>
</plugin>

The problem is that when I execute mvn clean verify jacoco still reports classes that should have been excluded as my xml configuration points out. How can I configure it properly?

Andrew Kew

Your XML is slightly wrong, you need to add any class exclusions within an excludes parent field, so your above configuration should look like the following as per the Jacoco docs

<configuration>
    <excludes>
        <exclude>**/*Config.*</exclude>
        <exclude>**/*Dev.*</exclude>
    </excludes>
</configuration>

The values of the exclude fields should be class paths (not package names) of the compiled classes relative to the directory target/classes/ using the standard wildcard syntax

*   Match zero or more characters
**  Match zero or more directories
?   Match a single character

You may also exclude a package and all of its children/subpackages this way:

<exclude>some/package/**/*</exclude>

This will exclude every class in some.package, as well as any children. For example, some.package.child wouldn't be included in the reports either.

I have tested and my report goal reports on a reduced number of classes using the above.

If you are then pushing this report into Sonar, you will then need to tell Sonar to exclude these classes in the display which can be done in the Sonar settings

Settings > General Settings > Exclusions > Code Coverage

Sonar Docs explains it a bit more

Running your command above

mvn clean verify

Will show the classes have been excluded

No exclusions

[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-test) @ ** ---
[INFO] Analyzed bundle '**' with 37 classes

With exclusions

[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-test) @ ** ---
[INFO] Analyzed bundle '**' with 34 classes

Hope this helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to exclude directories from phpunit coverage report

From Dev

Open JaCoCo report in Intellij IDEA

From Dev

Maven - Exclude class files from war

From Dev

Maven: exclude dependency from shade plugin

From Dev

Conditionally exclude some resources in maven from war

From Dev

JaCoCo gradle plugin exclude

From Dev

Exclude Certain Database Objects from the Build Depending on Configuration Settings

From Dev

Maven - exclude folder from build

From Dev

maven jacoco: not generating code coverage report

From Dev

maven: exclude jar from JDK

From Dev

Exclude packages from Jacoco report using Sonarrunner and Gradle

From Dev

Maven site not link to Jacoco report

From Dev

How do I exclude files from karma code coverage report?

From Dev

JaCoCo coverage report setups(exclude test classes)

From Dev

Jacoco Report are not generated in the site

From Dev

Empty Jacoco report for Android Espresso

From Dev

Getting jacoco report from cucumber tests with gradle

From Dev

Exclude folder in jacoco coverage report

From Dev

Jenkins jacoco plugin empty report

From Dev

Maven Report Configuration vs Build Configuration

From Dev

Jacoco Coverage and Report Task with Ant

From Dev

babel-istanbul cover exclude file from report but keep to transpile

From Dev

How to exclude a class from Jacoco coverage?

From Dev

maven jacoco plugin does not generate coverage report

From Dev

Configuration of options from IConfigurationRoot not working?

From Dev

How to exclude and include properly classes, packages and jar classes, lib from the jacoco report (Instrumentation offline)

From Dev

How to exclude a line from jacoco code coverage?

From Dev

How can I exclude files of the Code Coverage of SonarQube using JaCoCo maven plugin

From Dev

rsync --exclude and --exclude-from not working

Related Related

  1. 1

    How to exclude directories from phpunit coverage report

  2. 2

    Open JaCoCo report in Intellij IDEA

  3. 3

    Maven - Exclude class files from war

  4. 4

    Maven: exclude dependency from shade plugin

  5. 5

    Conditionally exclude some resources in maven from war

  6. 6

    JaCoCo gradle plugin exclude

  7. 7

    Exclude Certain Database Objects from the Build Depending on Configuration Settings

  8. 8

    Maven - exclude folder from build

  9. 9

    maven jacoco: not generating code coverage report

  10. 10

    maven: exclude jar from JDK

  11. 11

    Exclude packages from Jacoco report using Sonarrunner and Gradle

  12. 12

    Maven site not link to Jacoco report

  13. 13

    How do I exclude files from karma code coverage report?

  14. 14

    JaCoCo coverage report setups(exclude test classes)

  15. 15

    Jacoco Report are not generated in the site

  16. 16

    Empty Jacoco report for Android Espresso

  17. 17

    Getting jacoco report from cucumber tests with gradle

  18. 18

    Exclude folder in jacoco coverage report

  19. 19

    Jenkins jacoco plugin empty report

  20. 20

    Maven Report Configuration vs Build Configuration

  21. 21

    Jacoco Coverage and Report Task with Ant

  22. 22

    babel-istanbul cover exclude file from report but keep to transpile

  23. 23

    How to exclude a class from Jacoco coverage?

  24. 24

    maven jacoco plugin does not generate coverage report

  25. 25

    Configuration of options from IConfigurationRoot not working?

  26. 26

    How to exclude and include properly classes, packages and jar classes, lib from the jacoco report (Instrumentation offline)

  27. 27

    How to exclude a line from jacoco code coverage?

  28. 28

    How can I exclude files of the Code Coverage of SonarQube using JaCoCo maven plugin

  29. 29

    rsync --exclude and --exclude-from not working

HotTag

Archive