Project Lombok

Wouldn’t it be nice if you were able to write

@Getter @Setter private int age = 10;

which would generate those boilerplate setters and getters into the compiled code without messing up your source code?
With Lombok you get this and some other cool features most Java developers have on their wish list – and without setup hassle!

Setup

The setup of lombok is as easy as it can be. For a simple project you only have to add the lib to the classpath.
If you use maven the only thing needed is to add this dependency:

<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>0.9.3</version>
  <scope>provided</scope>
 </dependency>

Yes this is all you need to do. The lombok.jar contains manifest and service entries honored by the jdk which enable lombok. Java >= 1.6 is required.
If you are interested in the magic that allows this look here javax.annotatin.processing.Processor and here java.lang.instrument.

Features

The features are listed here. In my opinion the most useful are @Cleanup, @Getter, @Setter and val. But all features seem very useful in some places.

Why you should try it

You should definitively have a look at the short video and the documentation of Lombok. Lombok is a simple but powerful project that is also very well documented.

Enjoy.

About the author

Daniel Schröter

2 comments

  • Heh, we added lombok to maven central just yesterday, you’re quick!

    Just to clarify, ‘val’ is an 0.10.0 feature, it’s not in 0.9.3 yet, and 0.10.0 final hasn’t been released yet either. Consider it a coming attraction 🙂

    — Reinier Zwitserloot (one of the core contributors to Project Lombok)

Recent Posts