Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't compile project when I'm using Lombok under IntelliJ IDEA

People also ask

How do you compile Lombok?

Adding the Lombok Plugin in IDE (Eclipse) Downloaded jar from https://projectlombok.org/download or use the jar which is downloaded from your maven build. Execute command in terminal: java -jar lombok. jar. This command will open window as show in the picture below, install and quit the installer and restart eclipse.

How do I compile a project in IntelliJ?

Select a module or a project you want to compile and from the main menu, select Build | Build Project ( Ctrl+F9 ). IntelliJ IDEA displays the compilation results in the Review compilation and build output.

How do I enable annotation processing in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Compiler | Annotation Processors.


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:

  1. Visit https://projectlombok.org/download
  2. Download the JAR file into the project lib directory (e.g., $HOME/dev/java/project/libs).
  3. Start the IDE.
  4. Click File ๐Ÿ – Settings.
  5. Expand Build, Execution, Deployment ๐Ÿ – Compiler ๐Ÿ – Annotation Processors.
  6. Ensure Enable annotation processing is checked.
  7. 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).
  8. Click Apply.
  9. Click Plugins.
  10. Click Marketplace.
  11. Set search field to: lombok
  12. Install Lombok.
  13. Click OK.
  14. Restart the IDE if prompted.
  15. Click File ๐Ÿ – Project Structure.
  16. Select Libraries.
  17. Click the + symbol to add a new project library (or press Alt+Insert).
  18. Select Java.
  19. Set the path to: $HOME/dev/java/project/libs/lombok.jar
  20. Click OK.
  21. Select the modules to apply.
  22. Click OK.
  23. Optionally, rename lombok to Project Lombok 1.18.8.
  24. 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. enter image description here

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:

enter image description here


  1. 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'
     ...
 }
  1. Install Lombok plugin for your IDE
  2. Check "Enable annotation processing" checkbox in IDE (IntellijIdea), have no idea if there is anything like this for other IDEs like Eclipse.

in the latest Gradle version you should use annotationProcessor:

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok:1.18.8'

I'm using IntelliJ IDEA 2020.3 (Community Edition)

Here, besides install the Lombok plugin and enable annotations (explained by other answers). I also needed to set the flag -Djps.track.ap.dependencies=false to the Build Process Optionยน.

I didn't need to use the -javaagent approach, neither setup the classpath.

ยน. Go to: File | Settings | Build, Execution, Deployment | Compiler | "Shared build process VM options" field

References:

  • https://github.com/rzwitserloot/lombok/issues/2592#issuecomment-705449860
  • https://youtrack.jetbrains.com/issue/IDEA-250718#focus=Comments-27-4418347.0-0

Just for reference using IntelliJ 2018.3, I solved this issue (using @Data annotation to insert getter/setter) following the three steps:

  1. File -> Settings -> Build, Execution, Deployment -> Annotation Processors -> Enable Annotation Processing;

enter image description here

Do remember to Apply the change.

  1. Install plugin lombok in the same setting dialog;

enter image description here

  1. It seems good enough for now, it requires to restart IntelliJ and then rebuild your project.

Best wishes :)