18

With the cobertura-maven-plugin setters and getters can be excluded from code coverage using the ignoreTrivial option. Is there also such a possibility with the jacoco-maven-plugin?

This is my current configuration:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.7.1.201405082137</version>
  <configuration>
    <excludes>
      <exclude>com/welovecoding/web/blog/test/**/*.class</exclude>
    </excludes>
  </configuration>
  <executions>
    <execution>
      <id>amend-unit-test-java-agent-option</id>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
</plugin>
3
  • Are you still looking for an answer, possible for Gradle? Apr 26, 2015 at 3:26
  • Yes, I am still looking for an answer!! :-)
    – Benny Code
    Apr 26, 2015 at 7:10
  • 1
    What about <exclude>some/package/model/**/*</exclude> and <exclude>some/package/dto/**/*</exclude> when u have packages which contains mostly trivial code ?
    – Tristan
    Jun 18, 2020 at 13:14

3 Answers 3

16

From JaCoCo 0.8.0, it is possible to exclude the getters / setters (and also toString(), equals(), ...) automatically generated by Lombok from the coverage metrics thanks to filtering options :

Lombok

Methods annotated with @lombok.Generated (generated by Lombok getters, setters, equals, hashcode, toString, etc) - Done in 0.8.0

To that end, you will first need to create a lombok.config file located for example at the root folder of your projet, with the following contents :

lombok.addLombokGeneratedAnnotation = true

The @Generated annotation will be added to the setters / getters, etc. and will be skipped in the coverage analysis.

0
13

Not supported officialy, see comments in :

https://github.com/jacoco/jacoco/issues/15

mentioned solution:

It's a long time since this issue is opened. It a really interesting feature. For instance it's implemented in clover and corbetura. There are fork that implement filtering : github.com/huangxiwei/jacoco , https://github.com/mchr3k/jacoco since the begining of the year. Why don't you merge those fork into master branch ? Even if all filtering is not implemented at start, main filters needed are listed in the wiki page you have written (Try with resources, sync block, enum static methods). Coverage is a very useful tool, more it's accruate more it's will be usefull. It helps alot when coverage reach a high value, it helps to focus on the right classes.

1
  • Thanks for sharing that link! I wrote to the GitHub issue. Maybe there will be enough votes to get this feature.
    – Benny Code
    Oct 21, 2014 at 11:27
-7

I recommend to use Cobertura that does not have such limitation and also does not have so many false positive warnings.

2
  • False positive about what ?
    – Grzesuav
    Mar 16, 2016 at 17:13
  • 5
    Cobertura has a barely existent community and has bare bones (at best) support for java 8.
    – Joseph
    Apr 27, 2016 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.