5

I created a lombok.config file in my root directory with the following content:

config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true

But the Lombok generated codes (Getters, Setters, Builders, etc) still appears on my Jacoco test report.

Jacoco version is 0.8.6 and Lombok version is 1.18.12.

How can I remove Lombok code from reports?

Rodrigo Rufino
  • 51
  • 1
  • 1
  • 2
  • 2
    Presumably, tell jacoco to ignore anything annotated with `lombok.Generated`. I don't, unfortunately, know how to do that, though. – rzwitserloot Dec 22 '20 at 16:57
  • @rzwitserloot Jacoco already does that since version 0.8. – Tom Dec 22 '20 at 17:00
  • 1
    Have you checked that your built code actually contains the `@Generated` (or `@lombok.Generated`) annotation? – Tom Dec 22 '20 at 17:01
  • Hmm, I just checked, and apparently, it doesn't contain the annotation. Take a look: `public String toString() { UserType var10000 = this.getUserType(); return "UserCreateRequestDTO(userType=" + var10000 + ", email=" + this.getEmail() + ", phone=" + this.getPhone() + ")"; }` – Rodrigo Rufino Dec 22 '20 at 17:10
  • 2
    You don't need to paste that code into the comments, it isn't formatted correctly anyway. So there are several things you should do: verify the file name is correct and not `lombok.config.txt` for example, verify if the location is correct, verify you've rebuild your code after you've added the config file. Verify lombok is up-to-date and not an older version by mistake. It must be 1.16 at least (yes you said you're using 1.18, but does your project really use that version? Verify that) – Tom Dec 22 '20 at 17:17
  • Just checked. Everything looks fine. The file is named `lombok.config` and it is in the right location (root directory, next to build.gradle file), the version is 1.18.12, and I rebuilt the code. – Rodrigo Rufino Dec 22 '20 at 17:26
  • Update: I rebuilt it with the IntelliJ button and now it added the @Generated annotation just fine. But when I build it using Gradle the annotation is not added. Why does it happen? – Rodrigo Rufino Dec 22 '20 at 18:01
  • Maybe your built root is different for Gradle, so it doesn't find that config file. – Tom Dec 22 '20 at 18:18

5 Answers5

1

I had the same problem, with added lombok.addLombokGeneratedAnnotation = true Lombok still didn't add any @Generated annotation during compilation. It generated all the getters and setters, but none of them were annotated. Hence our test coverage was like 15% instead of about 70% without getters etc.

Solution was picking ANY random Lombok annotation and using it as @lombok.Getter instead of importing import lombok.Getter; and then using @Getter. I have no idea why it somehow triggered adding @Generated annotation everywhere where they were supposed to be added, but hey, if it works, it works.

dinguspapaj
  • 85
  • 2
  • 8
  • 1
    I can't believe that worked. °L° Thanks! – schnickers Jun 23 '22 at 11:39
  • I do not understand, what exactly have you done? How could I exclude data classes from jacoco coverage reports? Where should I put all these annotations? – Evgenii Vorobei Sep 09 '22 at 16:22
  • A possible cause is that when you edit your code you force the the compiler rebuild the project, what is required because jacoco reads from the compiled code. Check also the response from GrowlingBadger. – MiguelSlv Mar 28 '23 at 10:38
1

Silly mistake by me, but my solution to this was simply doing a clean first then a build. I think gradle was being clever about what it had built and just introducing the lombok.config wasn't enough to trigger the rebuild. Once that was done, it worked as it should.

0

use @lombok.XXX instead of importing import lombok.Getter;

It really solve the problem。

but ,after my test,

upgrade the lombok to org.projectlombok:lombok:1.18.26+

the problem alse can be solved.

-3

You do not need to add any config properties, just add @Generated annotation along with @Data.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
  • 3
    This isn't the right thing to do because any code you write in that class will be marked as generated even though its not. Even if you have no custom code in a data class you still shouldn't add `@Generated` manually because it will be out of date as soon as someone else adds code later. – mjaggard Nov 28 '22 at 17:49
-3

Build once with lombok.addLombokGeneratedAnnotation = false which will cause the build fail with low coverage (assuming you have such rules configured).

After the failure, set lombok.addLombokGeneratedAnnotation back to true. Any consecutive builds should start passing again.

Can't explain why this happens, must be a Lombok bug.

Attila T
  • 577
  • 1
  • 4
  • 18