Questions tagged [lombok]

Project Lombok is a tool for reducing boilerplate code in Java through annotations and compile time code generation.

The details for project Lombok can be found at http://projectlombok.org/.

The primary functionality of Lombok is reducing the boilerplate code in JavaBeans by replacing all setters, getters, equals, hashCode and toString with a single @Data annotation on the class.

Many other useful features are offered and the project is under active development.

2384 questions
121
votes
12 answers

How to exclude property from Lombok builder?

I have a class called as "XYZClientWrapper" , which have following structure: @Builder XYZClientWrapper{ String name; String domain; XYZClient client; } What I want no build function generated for property XYZClient client Does Lombok…
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
113
votes
8 answers

Lombok @Builder and JPA Default constructor

I'm using project Lombok together with Spring Data JPA. Is there any way to connect Lombok @Builder with JPA default constructor? Code: @Entity @Builder class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long…
krzakov
  • 3,871
  • 11
  • 37
  • 52
107
votes
3 answers

Is it possible to add qualifiers in @RequiredArgsConstructor(onConstructor = @__(@Autowired))?

If I wanted to use the annotation @Qualifier on a constructor dependency injection, I would have something like the following: public class Example { private final ComponentExample component; @Autowired public…
Pau
  • 14,917
  • 14
  • 67
  • 94
102
votes
14 answers

Required arguments with a Lombok @Builder

If I add @Builder to a class. The builder method is created. Person.builder().name("john").surname("Smith").build(); I have a requirement where a particular field is required. In this case, the name field is required but the surname is not.…
jax
  • 37,735
  • 57
  • 182
  • 278
96
votes
9 answers

Default value in lombok. How to init default with both constructor and builder

I have an object @Data @Builder @NoArgsConstructor @AllArgsConstructor public class UserInfo { private int id; private String nick; private boolean isEmailConfirmed = true; } And I initialize it in two ways UserInfo ui = new…
Vitalii
  • 10,091
  • 18
  • 83
  • 151
92
votes
5 answers

Kotlin doesn't see Java Lombok accessors?

Using Kotlin 1.0.0 release (compiling in IntelliJ 15). println(myPojoInstance.foo) When it tries to compile code (in IntelliJ or Gradle) that references Lombok based POJOs it gives the error "Cannot access 'foo': it is 'private' in "MyPojo". Which…
Chris Kessel
  • 5,583
  • 4
  • 36
  • 55
92
votes
5 answers

Lombok how to customise getter for Boolean object field?

One of my POJOs has a Boolean object field to permit NULLS in the database (a requirement). Is it possible to use the @Data Lombok annotation at class level yet override the getter for the Boolean field? The default it generates is getXXX method…
Paddy
  • 3,472
  • 5
  • 29
  • 48
90
votes
4 answers

View lombok generated code in IntelliJ IDEA

I have the lombok plugin setup in IntelliJ and my code builds fine. I can see the lombok generated methods in the structure view. What I want is some way to actually see the source lombok generates for each of the methods. I realize I can delombok…
Mike Sweeney
  • 1,896
  • 2
  • 18
  • 20
84
votes
12 answers

Lombok's access to jdk.compiler's internal packages incompatible with Java-16

Simply upgrading one of my projects from Java-15 to 16 (using the latest build here). On compiling the project which uses lombok such as: org.projectlombok lombok
Naman
  • 27,789
  • 26
  • 218
  • 353
80
votes
4 answers

Maven Scope for Lombok (Compile vs. Provided)

I recently found out that the lombok.jar ends up in our final artifact, which shouldn't be necessary. In my understanding lombok is compile-time only. org.projectlombok
mkraemerx
  • 1,713
  • 2
  • 17
  • 21
79
votes
22 answers

Cannot make Project Lombok work on Eclipse

I have followed the tutorial here http://projectlombok.org/ but after adding import and @Data nothing happens. Does it work on eclipse helios ?
user310291
  • 36,946
  • 82
  • 271
  • 487
78
votes
5 answers

Lombok @builder on a class that extends another class

I have two classes Child extends Parent. I need to put @Builder annotation on the classes such that I do not need to create the builder my self. package jerry;// Internal compiler error: java.lang.NullPointerException import…
zur
  • 1,121
  • 1
  • 11
  • 21
75
votes
12 answers

Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.code.TypeTags when using lombok

I have following dependency in pom.xml: org.projectlombok lombok 1.16.8 When I run mvn clean install, I have following error: Caused by:…
Thomas
  • 1,805
  • 1
  • 15
  • 31
72
votes
6 answers

Lombok getter/setter vs Java 14 record

I love project Lombok but in these days I'm reading and trying some of the new features of java 14. Inside the new capability, there is the record keyword that allows creating a class with already built-in the following functionality: constructor,…
gixlg
  • 1,193
  • 1
  • 9
  • 21
72
votes
6 answers

Use custom setter in Lombok's builder

I have a custom setter in my Lombok-based POJO: @Data @Builder public class User { private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder(); private String password = null; public void setPassword(String password) { …
Jan Nielsen
  • 10,892
  • 14
  • 65
  • 119