Search code examples
jacocolomboktest-coverage

How to ignore lombok.@UtilityClass for Jacoco?


I have used lombok.@UtilityClass to:

  • generate a private constructor
  • make the class final
  • make all fields in the utility class static

And Jacoco does not cover Lombok generated code. If I explicitly define a private constructor, Jacoco can recognize it.

So, any way to avoid coverage penalty due to usage of @UtilityClass?


Solution

  • Well, it turns out that the same can be done to solve this, as what we do to ignore any Lombok generated code: add lombok.config file in the project root with these lines:

    # this is root dir and don't search for parent
    config.stopBubbling = true
    # add @Generated and Jacoco will detect Lombok generated code and ignore them in reports
    lombok.addLombokGeneratedAnnotation = true