Lombok is an opensource project that reduces boiler plate code in the Java Pojo's by using annotations in the class. The main advantage of Lombok is to get rid of generating getters & setters (although the IDE generates it).
The source code can be found in GitHub.
Lombok in Action:
Add the dependency in pom.xml
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.2</version> <scope>provided</scope> </dependency>
import lombok.Getter; import lombok.Setter; @Getter @Setter public class Book { private int id; private String name; private String author; }
Other useful Annotations:
@ToString
@Builder
@NoArgsConstructor
@RequiredArgsConstructor
@EqualsAndHashCode and lot more ..
IDE's like Eclipse & IntelliJ does not detect the lombok annotations by default.
Lombok in IntelliJ:
Go to File → Settings → Plugins → Browse Repositories. Search for lombok.
Lombok in Eclipse:
Download Lombok and run the Jar. Specify the eclipse location and click Install.
Check the eclipse installation of lombok in About eclipse.
Other useful Reference: