Lombok annotations do not compile under Intellij idea
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
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.

