Lombok annotations do not compile under Intellij idea
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Lombok is a popular Java library used to help reduce boilerplate code especially in model/data objects by using annotations to generate common code such as getters, setters, toString(), equals(), and hashCode() methods. However, sometimes developers face issues where Lombok annotations do not seem to compile correctly in IntelliJ IDEA, one of the most popular IDEs for Java development.
Understanding the Problem
The issue generally arises because IntelliJ IDEA does not automatically process annotations the way a typical Java compiler does. Lombok operates by leveraging the annotation processors of the Java compiler to generate the required Java code during the compilation phase. However, IntelliJ uses its own build system, which does not enable annotation processing by default. As a result, it does not automatically recognize the getters, setters, or other methods that Lombok should generate, leading to numerous cannot find symbol errors in the IDE.
Configuring IntelliJ IDEA to Work with Lombok
To resolve issues with Lombok in IntelliJ IDEA, follow these steps:
- Ensure Lombok Plugin is Installed: IntelliJ IDEA requires a plugin to support Lombok. This can be installed by navigating to
Settings->Plugins, then searching for "Lombok Plugin". Install the plugin and restart the IDE to enable it. - Enable Annotation Processors: Go to
Settings->Build, Execution, Deployment->Compiler->Annotation Processors. Check the option "Enable annotation processing". This setting instructs IntelliJ to handle the annotation processing that Lombok uses. - Configure Lombok Dependency: Ensure your project’s
pom.xml(for Maven) orbuild.gradle(for Gradle) file explicitly declares the Lombok dependency:
- Rebuild the Project: After setting up the plugin and enabling annotation processing, rebuild your project. This can be done by clicking
Build->Rebuild Project.
Common Pitfalls
- Incorrect Lombok Version: Using an incompatible version of Lombok with your JDK can lead to issues. Always verify that the Lombok version in your
pom.xmlorbuild.gradlematches the JDK version used in your project. - Plugin Updates: Sometimes, the Lombok plugin is out of sync with the latest IntelliJ IDEA updates. Regularly check and update the plugin.
Examples of Lombok Usage
Using Lombok can significantly compact your codebase. Below is an example comparing traditional Java code and Lombok-enhanced code:
Summary Table
| Aspect | Without Lombok | With Lombok |
| Boilerplate Code | High | Low |
| Error Prone | More likely | Less likely |
| Code Conciseness | Less concise | More concise |
Conclusion
While initial configuration in IntelliJ IDEA might seem cumbersome, the benefits of using Lombok in reducing boilerplate code and improving code clarity are substantial. Following the correct setup steps ensures a smoother development experience.
Related reading
- Lombok is not generating getter and setter
- Long vs Integer, long vs int, what to use and when?
- Loop doesn't see value changed by other thread without a print statement
- Lossless JPEG Rotate 90/180/270 degrees in Java?
- Mac OS X and multiple Java versions
- Machine learning challenge diagnosing program in java/groovy datamining, machine learning
- Main differences between SOAP and RESTful web services in Java
- make arrayList.toArray return more specific types

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.