#Lombok #ProjectLombok #SpringBoot
For help and support - https://www.buymeacoffee.com/almighty...
What is Project Lombok?
Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.
Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more.
Here are some popular annotations
@NotNull
@Getter
@Setter
@ToString
@EqualsAndHashCode
@NoArgsContructor
@AllArgsContructor
@RequiredArgsConstructor
@Data
@Value
@Builder
@Synchronized
@SneakyThrows
@Slf4j
Advantages of using Project Lombok
When choosing a new library or a tool, you always need to take into consideration some aspects in order to increase your chances of success, and Lombok is no exception.
In this section, we discuss the advantages of using Lombok and some scenarios where Lombok would make sense.
Lombok saves you time
Let us get into the interesting stuff first. If you have checked our articles here and here, you will see examples of how much time you can save by using Lombok. Mindless hours of boilerplate code can be reduced to a few class annotations.
This not only saves you time, but theoretically money as well (time is money you know). Think about all the paid time your team spends writing getters and setters, renaming them when renaming a variable, etc.
If your project has a lot of DTOs and POJOs, then it might be a good idea to consider using Lombok.
Lombok is opensource
Project Lombok is an open source library. This means that you are not required to pay for it to use in your enterprise application. There is also a large community behind it, which means that issues are readily raised with the development team and are dealt with in future updates.
Another advantage of open source projects is that they are used by numerous other developers. This means that you can find answers to your questions on support forms.
Disadvantages of using Project Lombok
As with any library, there are pitfalls that you need to be careful of when using it. With Lombok, you can avoid these pitfalls if you know what you are dealing with and by not leaning too much on it.
Delomboking code can be difficult
If you google “disadvantages of project Lombok”, you will find a wide variety of posts by developers complaining how difficult was it for their team to move away from Lombok.
Lombok provides a tool to convert the Lombok annotations to their equivalent vanilla Java code. This tool is called Delombok. Delomboking your code can be done either through the command line or via your IDE.
However, as with any code generation or handling tool, it does not always produce the perfect result. So it might not be a good idea to use Lombok in each and every single Java class you have as it might be difficult to move back to plain Java later on if you need to.