JaCoCo: exclude generated methods (using it with Lombok)

Federico Tomassetti picture Federico Tomassetti · Apr 8, 2015 · Viewed 22.6k times · Source

I am using JaCoCo and it is considering methods generated by Lombok (generated in the bytecode, not trace of them in the source code). How can I configure JaCoCo to ignore them?

Answer

ebonnet picture ebonnet · Aug 14, 2018

Also another way to exclude lombok generated classes since jacoco 0.8.0 and lombok 1.16.14 see: https://www.rainerhahnekamp.com/en/ignoring-lombok-code-in-jacoco/

Luckily, beginning with version 0.8.0, Jacoco can detect, identify and ignore Lombok-generated code. The only thing you as the developer have to do is to create a file named lombok.config in your directory’s root and set the following flag:

lombok.addLombokGeneratedAnnotation = true

This adds the annotation lombok.@Generated to the relevant methods, classes and fields. Jacoco is aware of this annotation and will ignore that annotated code.

Please keep in mind that you require at least version 0.8.0 of Jacoco and v1.16.14 of Lombok.