Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JaCoCo: exclude generated methods (using it with Lombok)

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?

like image 207
Federico Tomassetti Avatar asked Apr 08 '15 17:04

Federico Tomassetti


People also ask

How do you exclude methods in JaCoCo code coverage?

You can set lombok. addLombokGeneratedAnnotation = true into lombok. config in the root of project. After that, all Lombok-generated code will be ignored by Jacoco.

What is @generated Lombok?

Lombok will eventually automatically add this annotation to all generated constructors, methods, fields, and types. As per the docs, @Generated annotation is automatically added by Lombok for the generated code. Apart from that, @Generated doesn't generate any code like @Getter or @Setter does.

What is missed instructions in JaCoCo report?

Instruction coverage provides information about the amount of code that has been executed or missed. This metric is completely independent from source formatting and always available, even in absence of debug information in the class files.

Why is JaCoCo not showing coverage for some classes?

Why does the coverage report not show highlighted source code? Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports: Class files must be compiled with debug information to contain line numbers. Source files must be properly supplied at report generation time.


1 Answers

Also another way to exclude lombok generated classes since jacoco 0.8.0 and lombok 1.16.14.

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.

like image 88
ebonnet Avatar answered Sep 23 '22 12:09

ebonnet