Improve Lombok @Data Code Coverage
First of all, @Data annotation is the combination of @ToString, @EqualsAndHashCode, @Getter, @Setter.
If you just need Lombok to create getters and setters automatically, you can use only @Getter and @Setter annotations instead of @Data.
Besides, to keep the methods created by Lombok outside of this coverage, you can create a lombok.config file in your root directory and have these two lines:
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
After adding this line, when you go to Sonar, you will see that these classes are covered 100%.
In 0.8.0 release, Jacoco added support for filtering out all methods annotated with @lombok.Generated
from their reports. The only thing you need to change is to add lombok.config
to the root of your project with the following settings:
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
config.stopBubbling = true
tells Lombok that this is your root directory and that it should not search parent directories for more configuration files (you can have more than one lombok config files in different directories/packages).lombok.addLombokGeneratedAnnotation = true
will add @lombok.Generated annotation to all Lombok generated methods.
And that's it. Jacoco will filter Lombok auto-generated methods, and if you give your best, your code coverage could be close to 100% :))