Can't compile project when I'm using Lombok under IntelliJ IDEA
I have fixed it in IDEA 12 by setting check box Enable annotation processing
in:
Settings -> Compiler -> Annotation Processors
For IDEA 2016.2:
Preferences... > Build, Execution, Deployment > Compiler > Annotation Processors
After enabling, run Build -> Rebuild Project to have annotations recognized and eliminate errors.
For IDEA 2019.2.1, depending on how the project is configured, installing the Project Lombok plugin may not be sufficient. Here is another way to use Project Lombok with IntelliJ IDEA:
- Visit https://projectlombok.org/download
- Download the JAR file into the project lib directory (e.g.,
$HOME/dev/java/project/libs
). - Start the IDE.
- Click File đź – Settings.
- Expand Build, Execution, Deployment đź – Compiler đź – Annotation Processors.
- Ensure Enable annotation processing is checked.
- Ensure Store generates sources relative to is selected based on the project's module settings (if Module output directory doesn't work, come back and try the other setting).
- Click Apply.
- Click Plugins.
- Click Marketplace.
- Set search field to:
lombok
- Install Lombok.
- Click OK.
- Restart the IDE if prompted.
- Click File đź – Project Structure.
- Select Libraries.
- Click the + symbol to add a new project library (or press Alt+Insert).
- Select Java.
- Set the path to:
$HOME/dev/java/project/libs/lombok.jar
- Click OK.
- Select the modules to apply.
- Click OK.
- Optionally, rename
lombok
toProject Lombok 1.18.8
. - Click OK.
The project can now import from the lombok
package and use Project Lombok annotations (e.g., lombok.Setter
and lombok.Getter
).
Enabling annotation processing will make it work
But if you are on a Mac, make sure you enable annotation processing(tick the checkbox) from both the places available.
1.) Intellij Idea -> Preferences -> Compiler -> Annotation Processors
2.) File -> Other Settings -> Default Settings -> Compiler -> Annotation Processors
Picture representation of resolving this issue.
First enable annotation processors and try. This may or may not work.
Post that, you can install the lombok plugin from intellij, (After installation Intellij will restart to enable the plugin, so make sure you save your work.(Intellij does save all the changes before restart, just to be on the safe side.)) screenshot below:
- Make sure it's added correctly to your project.
example for Gradle:
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
...
}
- Install Lombok plugin for your IDE
- Check "Enable annotation processing" checkbox in IDE (IntellijIdea), have no idea if there is anything like this for other IDEs like Eclipse.