60

I'm trying to add Lombok to my Spring Boot project in IntelliJ IDEA. So far, I've

  1. added the plugin under Settings - Plugins (version 0.13.16)

  2. added compile('org.projectlombok:lombok') to my Gradle dependencies

  3. enabled annotation processing

It still doesn't recognize either the Lombok import or the annotations.

What am I missing?

Solved:

I had to run an update on my Gradle file.

SOLO
  • 868
  • 9
  • 19
Anders Pedersen
  • 2,255
  • 4
  • 25
  • 49

10 Answers10

75

You need to Enable Annotation Processing on IntelliJ IDEA

> Settings > Build, Execution, Deployment > Compiler > Annotation Processors

enter image description here

A0__oN
  • 8,740
  • 6
  • 40
  • 61
  • 3
    Thanks. A bit weird that you have to enable this option after installing the Lombok plugin, though. They should have at least pointed to this option in their instructions. – Ammaro Mar 15 '18 at 01:29
  • I don't have it enabled and Lombok is recognized (after installing the plugin and restarting). Maybe this is not necessary anymore? – Ferran Maylinch May 28 '18 at 15:00
  • 1
    Adding the Lombok plugin is necessary for runtime usage. Activating the annotation processing is necessary for compile time usage to get rid of the compiler warnings in the editor window. – bl4ckb0l7 Apr 17 '19 at 14:28
42

To add the Lombok IntelliJ plugin to add lombok support IntelliJ:

  • Go to File > Settings > Plugins
  • Click on Browse repositories...
  • Search for Lombok Plugin
  • Click on Install plugin
  • Restart IntelliJ IDEA
Vikash
  • 643
  • 7
  • 13
  • 1
    This is correct approach followed by @Henrik's steps and enabling "Annotation processing" under `Build, Execution and deployment` section in `Settings`. – instinct Nov 30 '18 at 09:08
15

Be sure to activate the plugin for the project in the Intellij settings.

  1. Click Settings Other Settings Lombok Plugin.
  2. Ensure Enable Lombock plugin... is checked.

Lombok Plugin Settings

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Henrik Kirk
  • 604
  • 1
  • 6
  • 18
8

To install the plugin manually, try:

  1. Download Lombok zip file (ensure Lombok matches the IDE version).
  2. Select Preferences Plugins Install Plugins from Disk.

IntelliJ Plugin Preferences Dialog

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Naveen
  • 907
  • 2
  • 15
  • 25
5

There is a lot of really helpful info posted here, but there is one thing that all the posts seem to have wrong. I could not find any 'Settings' option under 'Files', and I hunted around for 10 minutes looking through all the menus until I found the settings under 'IntelliJ IDE' -> 'Preferences'.

I don't know if I am using a differing OS version or IntelliJ version from other posters, or if it is because I am a stupid Windows user that doesn't know that settings == preferences on a mac (Did I miss the memo?), but I hope this helps you if you aren't finding the paths that other posts are suggesting.

Roger Hill
  • 3,677
  • 1
  • 34
  • 38
  • ...and that's why I love people posting screenshots; the world's between win and mac and its wordings annoyances are a step clearer then ;-) I also think that these troubles sometimes consumes too much time. Did anyone mention the differences between versions of a software ;-) – Dirk Schumacher May 01 '21 at 19:55
5

I would like to add that in my case (My OS is Linux Mint and using IntelliJ IDEA). My compiler complaining about these annotations I was using: @Data @RequiredArgsConstructor, even though I had installed and activated the Lombok plugin.Install Lombok in IntelliJ Idea. I am using Maven. So I had to add this dependency in my configuration file (pom.xml file):

dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>
RanaIssa
  • 61
  • 1
  • 3
4

If after installing the lombok intellij plugin and enabling annotation processing, if your getter and setters are still not recognised in intellij, do check if the plugin version is compatible with the intellij version you use.

It is listed under the Downloads section:

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Mohammed Rafeeq
  • 2,586
  • 25
  • 26
2

For me it didn't work after doing all of the steps suggested in the question and in the top answer. Initially the import didn't work, and then when I restarted IntelliJ, I got these messages from the Gradle Plugin:

Gradle DSL method not found: 'annotationProcessor()'
Possible causes:<ul><li>The project 'wq-handler-service' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 2.3.2 and sync project</li><li>The project 'wq-handler-service' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>

This was weird because I don't develop for Android, just using IntelliJ for Mac OS.

To be fair, my build.gradle file had these lines in the dependencies section, which I copied from a colleague:

compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.20'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.16.20'

After checking versions, the only thing that completely solved my problem was adding the below to the plugins section of build.gradle, which I found on this page:

id 'net.ltgt.apt' version '0.15'

Looks like it's a

Gradle plugin making it easier/safer to use Java annotation processors

(ltgt plugin page)

Swagga Ting
  • 602
  • 3
  • 17
1

I just found how.

I delete the first occurrence of lombok @Slf4j or log where the compiler complains, and wait for the warning(the red bubble) of IDEA, suggesting "add the lombok.extern.Slf4j.jar to classpath". Since then all goes well. It seems IDEA likes to complain about lombok.

WesternGun
  • 11,303
  • 6
  • 88
  • 157
1

I had the same problem after updating IntelliJ IDE, the fix was: delete existed plugin lombok and install it again (the newest version),

Egor
  • 2,122
  • 2
  • 21
  • 23