Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lombok slowing down build process in large project

If I use Lombok in a project (about 15 separate projects - EJB, Web,...) Lombok slows down the build Process about 2-3 times. Is there any solution for this, or is that a disadvantage of Lombok?

Just to see the size of the project, it's about 400 @Getter, 120 @Data, 250 @Setter and 100 @EqualsAndHashCode.

Environment: IBM Rational Application Developer 8.0.4 with newest Version of Lombok (0.11.6)

Any ideas to make it faster?

like image 841
anm Avatar asked Mar 20 '13 08:03

anm


People also ask

What is the disadvantage of Lombok?

One potential disadvantage to something like Lombok is that with the setters/getters "missing", source tools may not "recognize" aspects of the resulting object that give it "bean" qualities, since those qualities only manifest in the compiled class.

Is using Lombok a good practice?

Lombok is just a tool to make your life easy. It does not provide any assistance or support for clean code. If clean code and design principles are not of importance (trust me it's not that bad as it sounds in most of the cases), then using Lombok to simplify development process is the best option.

Is Lombok compile time or runtime?

Lombok acts as an annotation processor that “adds” code to your classes at compile time. Annotation processing is a feature added to the Java compiler at version 5.


2 Answers

Lombok is an annotation processor (a compiler plugin, if you want). At compile time, it gets called each time a particular set of annotations is found in your code, and is given the opportunity to generate new sources or throw compiler errors. If anything new is generated during a compilation round, another one must take place, until all has been successfully compiled. So yes, it takes time to find the annotations, process them as required (see below), and to run the extra compilation rounds.

The Annotation processor specification explicitely forbids them to modify existing code - you can produce new classes or extra files (.properties, etc), but not change the existing code. Lombok goes around that by detecting the compiler used, and hacking its internal APIs to change the AST in-memory to add accessors and such. This is just... terrible.

And this is, in my opinion, a major technological risk. In the end, Lombok does nothing your IDE can't do - generate accessors, etc., but could endanger your whole project - what if you upgrade your compiler and Lombok does not support it, or introduces a bug ? You end up with a non-compiling code (or in your case, a very slow compilation), only to hide some boilerplate methods that do no harm except take a few lines in your code. But that's just my opinion :)

So to come back to your problem, I don't see how you could get better compilation times, except by removing Lombok alltogether.

like image 170
Olivier Croisier Avatar answered Oct 18 '22 22:10

Olivier Croisier


Finally, there is an edge-build available, which speeds up Lombok very much! They did a lot of work speeding it up, it works fine for me now. The build time was nearly halved and I do not have to wait every time saving a file.

I also delomboked my project to get a comparison in speed and it is not very much difference between the delomboked code and the code with lombok-annotations.

You can download the edge-build here: http://projectlombok.org/download-edge.html

like image 40
anm Avatar answered Oct 18 '22 23:10

anm