Andy
Andy

Reputation: 6329

what is the use of @Generated Lombok annotation

In my project codebase, I see @Generated annotation being used in many places. When I read through the docs it states the following.

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. I don't see the rationale in using this.

Am I missing something here?

Upvotes: 16

Views: 20720

Answers (1)

Andy
Andy

Reputation: 6329

I came across one valid use case for @Generated. So I thought I will update here hoping it might help someone sometime.

In our project, we use Jacoco to generate a coverage report. There are a few classes and methods that don't make sense to be a part of the coverage report. Eg: configuration classes, POJOs, close() etc.

Classes can be excluded from the report by using the <exclude> tag in POM.xml. But If you would like to ignore only one method from a class, you can't achieve that by adding entries in pom.xml.

In scenarios like that, we can use @Generated annotation on methods to be excluded from the coverage report. Cheers.

Upvotes: 29

Related Questions