277

I'm trying to use Lombok in my project that I'm developing using IntelliJ IDEA 11.

I've installed 3rd-party plugin for IDEA and it seems working fine because IDEA sees all autogenerated methods/fields.

So I have a class that uses Slf4j. I annotated it like this

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestClass
{
    public TestClass()
    {
        log.info("Hello!");
    }
}

But when I build my project compiler spits: cannot find symbol variable log.

Could you please tell me what I'm missing here?

Update: It turned out it's RequestFactory annotation process that fails.

input files: {com.zasutki.courierApp.server.TestServlet, com.mine.courierApp.server.model.DatastoreObject}

annotations: [javax.inject.Singleton, javax.inject.Inject, lombok.Getter, lombok.Setter, com.googlecode.objectify.annotation.Id, com.googlecode.objectify.annotation.OnSave]

Processor com.google.web.bindery.requestfactory.apt.RfValidator matches [lombok.Getter, com.googlecode.objectify.annotation.Id, javax.inject.Inject, lombok.Setter, com.googlecode.objectify.annotation.OnSave, javax.inject.Singleton] and returns false.

cannot find symbol variable log

Any ideas on workarounds?

Update2: Perhaps it's not something readers want to hear but I ended up switching to Scala.

Or Assayag
  • 5,662
  • 13
  • 57
  • 93
expert
  • 29,290
  • 30
  • 110
  • 214
  • Errors appear even without the plugin. I am not able to run tests of a project if Lombok is in my pom.xml dependencies. – Nowaker Feb 26 '12 at 21:57
  • there is another answer https://stackoverflow.com/a/63632563/5410940 – Error Hunter Aug 28 '20 at 11:11
  • Answers below all assume that lombok is working. You may need to add a shared VM option to make that happen. See -https://stackoverflow.com/a/65188047/529659 – jomofrodo Aug 31 '22 at 22:04

45 Answers45

508

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).

Community
  • 1
  • 1
user2021572
  • 5,112
  • 1
  • 13
  • 3
  • I had to stop my Win10 for a freeze issue (pilot crash) and IntelliJ was opened. At restart, I guess idea files in my project directory has been altered (workspace.xml) and after that I couldn't generate my getters/setters methods via lombok. "Canno't find symbol" at build time. I wrestled a bit to spot the origin of the issue. – Alex May 20 '16 at 08:42
  • 2
    Don't forget to set annotation processor: lombok.launch.AnnotationProcessorHider$AnnotationProcessor for both maven-compiler-plugin and Idea (Settings -> Compiler -> Annotation Processors) – Jan Kubovy Jun 15 '16 at 15:38
  • 4
    This isn't working for me in 2016.2. Maven web project. The only thing that worked was installing the lombok plugin. – maksimov Sep 15 '16 at 10:24
  • Idea 16.2.2 + gradle + installed lombok plugin. I could run project without this when using the gradle runscript (from idea). If I wanted to run directly (since this is the only way I know to make code hotswap work) I had to enable annotation processing. Guess idea does not automatically fully configure project and annotations don't get processed despite the plugin? – Neikius Oct 20 '16 at 15:20
  • Worked for me in IDEA 2017.01. Installing Lombok worked for Intellisense, but not for compilation until Annotation Processor was enabled. – lreeder May 24 '17 at 16:38
  • For IDEA 2017.3.2, re-installing the Lombok plugin (Uninstall, restart, Install and restart) worked for me. – Antonio Saco Jan 09 '18 at 11:33
  • After doing it, I still needed to remove and reimport the project as a maven project – Carlos Alberto Schneider Jul 23 '18 at 17:28
  • Without the plugin the above is irrelevant. Install the Lombok plugin AS WELL AS the good advice in the answer above :=). Also applies to Intellij 2018.2 btw. – Beezer Mar 18 '19 at 13:38
  • In my case, I wasn't seeing a warning message before the errors, saying that plugin Lombok had been disabled because of [delegating issues](https://github.com/mplushnikov/lombok-intellij-plugin/issues/620). Turned out Idea was trying to use Java 11 to compile. After downgrading to Java 1.8, everything worked fine. – user5365075 Jul 25 '19 at 12:58
  • Came here for the 2019 version update... thank you so much. – Stevers Dec 23 '19 at 17:40
  • 10
    in addition to above steps, I had to include the following lines to `build.gradle`: `annotationProcessor "org.projectlombok:lombok:1.18.8"` `testAnnotationProcessor("org.projectlombok:lombok:1.18.8")` – Gryk Jan 06 '20 at 09:59
  • 1
    @Gryk after adding your suggestion it worked in my application. Thank you. – KaraKaplanKhan Apr 13 '22 at 13:43
  • 1
    @Gryk +1 Solved for me... literally. tried. everything. -.-" – Eric Ballard Apr 22 '23 at 18:01
82
  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.
Yevhenii Tsybaiev
  • 1,025
  • 8
  • 7
78

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

CodeShadow
  • 3,503
  • 1
  • 17
  • 16
  • 4
    thank you.. I got the same problem. I forgot to install the plugin before I set the Annotation configuration :) – TYL Sep 15 '17 at 10:45
75

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

greperror
  • 5,156
  • 3
  • 20
  • 29
33

in the latest Gradle version you should use annotationProcessor:

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
Valeriy K.
  • 2,616
  • 1
  • 30
  • 53
27

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:

12

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 :)

Hearen
  • 7,420
  • 4
  • 53
  • 63
  • Did you had maven or gradle? I am having a problem making lombok work for a multi module project. I keep getting the error: `Error:java: Annotation processing is not supported for module cycles. Please ensure that all modules from cycle [module-core,module-utils] are excluded from annotation processing` – 0x01Brain Jun 04 '20 at 06:40
  • @0x01Brain I *was* using maven at that time, but now using gradle instead. As for your question, I do hope you can start a new specific question to describe the details and there are lots of experts out there will help you ;) – Hearen Jun 07 '20 at 07:14
  • never mind I got it to compile now, thanks. I had some conflict in depedencies module-core was imported in utils module and utils module was imported in core module which made a conflict. – 0x01Brain Jun 11 '20 at 18:02
10

If you have checked both these steps as follows

  1. Enable annotations : this is a check done in IntelliJ preferences.
  2. Importing lombok into IntelliJ classPath (Preferences -> Plugins)

and still getting errors then please check the compiler - if it is JAVAC or ECLIPSE.

You can check the compiler in Preferences -> Build,Execution,Deployment -> Compiler -> Java Compiler.

Change the Use compiler to Javac (if it is Eclipse). This is what worked for me.

Saurabh Saha
  • 962
  • 11
  • 18
10

Including the following in the pom.xml is what worked for me:

<build>
        <defaultGoal>spring-boot:run</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <annotationProcessorPaths>
...
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>       
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
</build>
7

As noted here, quote: "You should activate external compiler option and enable annotation processors or disable external compiler and disable all of annotation compilers to work with lombok". This fixed my problem. Note that I added the Scala plugin prior to receiving this error, so I suspect the plugin changed some of the above settings.

Omri Sivan
  • 339
  • 3
  • 8
7

there is a plugin for intellij. see here: https://projectlombok.org/download.html

mtuulu
  • 1,042
  • 1
  • 10
  • 14
  • 2
    This plugin can be installed in Settings/Plugins menu of Intellij. Make sure you have the latest plugin installed. Upgrading to latest plugin worked for me. – CodeMonkey Jun 15 '16 at 17:44
5

Do you have lombok as dependency of your project? lombok.jar must be on the classpath during compiling of the project, which is using any of lombok-annotations.

mplushnikov
  • 104
  • 2
4

For those of you who are still having trouble:

In addition to the above steps of enabling annotation processors and installing the IntelliJ Lombok plugin, I also had to Build -> Rebuild Project.

JasnaRB
  • 91
  • 2
  • 3
  • 4
    I also had to invalidate the cache and restart before Intellij stopped complaining. – Hans Jun 29 '17 at 08:32
3

1、install lombok plugin for IDEA

Intellij Idea -> Preferences -> Plugins -> type in lombok -> Search in Repositories -> install -> restart IDEA

2、 config lombok plugin

Enabling annotation processing will make it work

But if you are on a Mac, make sure you enable annotation processing in the following two places:

Intellij Idea -> Preferences -> Build, Execution, Deployment -> Compiler -> Annotation Processors, check the checkbox of "Enable annotation processing". File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors, check the checkbox of "Enable annotation processing".

Bruce
  • 1,718
  • 20
  • 15
  • I don't see Default Settings in Other Settings in IntelliJ. Are these still present. I am using the Ultimate edition - version11.03 – thenakulchawla Jan 16 '20 at 18:06
3

I was on Mac

This is my IntelliJ IDEA and Mac Version - IntelliJ IDEA 2017.1.5 Build #IU-171.4694.70 --- Mac OS X 10.12

In addition to enabling annotation processing (tick the checkbox) at these 2 places.

1.) Intellij IDEA -> Preferences -> Compiler -> Annotation Processors

.

2.) File -> Other Settings -> Default Settings -> Compiler -> Annotation Processors

I had to install Lombok plugin too to make it work.

3.) Intellij IDEA -> Preferences -> Plugins ->Browse Repositories-> Search for "Lombok"-> install plugin -> Apply and restart IDEA

so-random-dude
  • 15,277
  • 10
  • 68
  • 113
3

It didn#t work for me with any of the above solutions. I added <scope>provided</scope> to the dependency in pom.xml and it worked.

<dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.20</version>
        <scope>provided</scope>
    </dependency>
2

If you did everything mentioned in this question and It's still failing, don't forget to remove /target folder under your projects. And If it's still failing, restart your IDE. And If it's still failing restart your computer.

Tugrul
  • 1,760
  • 4
  • 24
  • 39
2

I tried enabling lambok, restarted intellij, etc but below worked for me.

Intellij Preferences ->Compiler -> Shared Build process VM Options and set it to

  -Djps.track.ap.dependencies=false

than run

mvn clean install
LOrD_ARaGOrN
  • 3,884
  • 3
  • 27
  • 49
2

If you already installed it, then for refresh just deselect and select Enable annotation in Intellij Settings.

Tohid Makari
  • 1,700
  • 3
  • 15
  • 29
1

It may happen that even if you have it configured properly and it is visible among the libraries and in Gradle dependencies list, IntelliJ still does not have it in class path. Or it is there, but configured with different scope (ex: test instead of compile.)

First, make sure you have plugin installed and annotation processing enabled, as stated in other answers.

If you still have annotation not recognized, place cursor on it, hit ALT+ENTER (or OPTION+ENTER) and see if you have a menu option Add library: Gradle: org.projectlombok:lombok:VERSION to class path. If you can see it, choose this one and it may solve your problem.

You may check the library and it's scope in: Project settings / Modules / Dependencies tab (search for lombok in there)

wst
  • 4,040
  • 4
  • 41
  • 59
  • This solution should be much more upvoted. I was investigating this for hours, and this was the only thing that worked. – Devon Mar 12 '21 at 02:45
1

I have faced this problem after updating the IDEA to 2018.3. I had to update all the existing plugin

Srikanth Reddy
  • 119
  • 1
  • 5
1

After trying all the suggestions here, I have also find another kind of solution. It seems that sometimes IDEA can not obtain processors from project classpath.

So, on the Annotation Processors settings tab, you have to manually specify Processor path.

Stepan Mozyra
  • 212
  • 2
  • 6
1

Apart from mentioned in all answers I have to add the below code in pom.xml configuration to makes mvn clean install work. Before adding this code I was getting cannot found symbol for getters and setters.

                    <annotationProcessorPath>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.18.8</version>
                    </annotationProcessorPath>
Vaibhav K
  • 31
  • 6
1

For me what worked:

  1. I uninstalled the installed the Lombok plugin freshly
  2. I ticked "Enable Annotation Plugin"
  3. I selected "Obtain processor from the project classpath" in the same page
Sagiruddin Mondal
  • 5,407
  • 2
  • 29
  • 44
1

For IntelliJ IDEA 2020.1.1 enabling Kotlin plugin fixed this issue.

1

The Jetbrains IntelliJ IDEA editor is compatible with lombok without a plugin as of version 2020.3.

I was using 2020.2 version, i updated to 2020.3 it worked just like that.

Sasi Kumar M
  • 2,440
  • 1
  • 23
  • 23
1

I don't think I read my final step in the answers yet. (Mac + IntelliJ Ultimate 2020.1) Its just a silly cause in my case, but those are the ones that can take up most time because the error doesnt directly refer to it.

The same lombok error appeared to me after deleting and recloning the project. After doing the steps mentioned earlier in this thread I still had the error, I then discovered my SKD was defaulted to version 11. I changed this back to 1.8 and everything worked again.

File --> Project Settings --> Project I changed the Project SDK and the Project language level to 1.8

PS the location for the default settings on the mac is different in this IntelliJ version than mentioned before : File --> New Project Settings --> Preferences for new Projects --> Build, Execution, Deployment --> Compiler --> Annotation Processors --> 'check' Enable annotation processing

Hope this helps anybody

S Kampen
  • 41
  • 3
1

If none of the above did'nt work , then try to change File->Project Structure->Project->Project Language Level > 8 Lambda,type annotations (Not SDK Default 8)

This worked for me .

Dhiraj Surve
  • 310
  • 2
  • 5
0

I had a similar issue when building with JDK8, set the project back to JDK7 and it worked fine. Could be an older version of Lombok that won't compile under JDK8.

John Chapman
  • 878
  • 3
  • 14
  • 28
0

If you tried all solutions presented here and still can't compile sources, also look here: Static import of builder class breaks bytecode generation in Maven - look at your sources if it has such static imports. This affects maven plugin, so compilation will fail on other build systems outside IntelliJ IDEA.

cybersoft
  • 1,453
  • 13
  • 31
0

In my case, I had all the things mentioned below in place and it still wasn't working.

  1. I had lombok plugin installed correctly
  2. Annotation Processors, also checked.
  3. My Java compiler was set to JAVAC

To fix my issues I had to

  1. Update lombok to the latest version (v0.15) as at 7, Oct, 2017.
  2. Restart IntelliJ.
  3. Rebuild project.

See screenshots on how to update and rebuild project below.

How to update lombok

How to rebuild project

0

You can fix cannot find symbol variable log when using lombok in IntelliJ IDEA 2017.1.3 by doing this:

IntelliJ Preferences > Build, Execution, Deployment > Annotation Processors > [Check] Enable annotation processing > Apply

realPK
  • 2,630
  • 29
  • 22
0

Install the below plugin and restart the IDE to resolve the errors:

File -> Settings -> Plugins-> Browse Repositories -> Lombok Plugin

Enable annotation processor:

File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors
File -> Other Settings -> Default Settings -> Compiler -> Annotation Processors
firstpostcommenter
  • 2,328
  • 4
  • 30
  • 59
0

I faced a similar problem. The following worked for me.

download (from here https://projectlombok.org/download) and add the jar in your project structure.

Steps: File -> Project Structure -> Global Libraries

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Mr Nobody
  • 388
  • 4
  • 11
0

If lombok libs are set correctly, as many mentioned above, click on the annotation that wouldn't compile, Alt-Enter, a correct import will appear, and the code will compile. - it took me a while to figure it out. I put it here just in case people may miss the simple obvious.

TGU
  • 181
  • 2
  • 7
0

For Eclipse users on MacOS, do this. It worked for me.

  1. Copy lombok.jar into Eclipse.app/Contents/MacOS directory.
  2. Add -javaagent:lombok.jar to the end of Eclipse.app/Contents/Eclipse/eclipse.ini file.
  3. Restart Eclipse and enable “Annotation Processing” in project properties.

Referencing this

Mark Jin
  • 2,616
  • 3
  • 25
  • 37
0

After enabling annotator processors I had to update to the newest version of lombok:

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.16</version>
    </dependency>

Intellij version:

IntelliJ IDEA 2020.3 (Community Edition)
Build #IC-203.5981.155, built on November 30, 2020
Runtime version: 11.0.9+11-b1145.21 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.16
GC: ParNew, ConcurrentMarkSweep
Memory: 1981M
Cores: 8
Non-Bundled Plugins: org.intellij.plugins.hcl, Lombook Plugin, org.sonarlint.idea, in.1ton.idea.spring.assistant.plugin, org.jetbrains.kotlin, gherkin, cucumber-java
Blink
  • 1,408
  • 13
  • 21
0

This happened to me because the JDK version that runs the building process is too low. Lombok was built with JDK 1.7 or up. The build be must run with Java version 1.7 or up.

enter image description here

0

I had to disable the @Document annotation that I'd just added. I'm converting my project to use Mongo instead of Postgres, and it was previously working, but it seems @Document conflicts with Lombok's @Getter

Dan Bitter
  • 229
  • 4
  • 12
0
  1. add Lombok plugin.
  2. In my case, just maven clean.
hatanooh
  • 3,891
  • 1
  • 14
  • 9
0

My issue was that the bundled version of Lombok plugin in IntelliJ IDEA was incompatible with the version of IntelliJ IDEA itself. I downgraded IntelliJ to 2019.1.4 and it worked.

enter image description here

banan3'14
  • 3,810
  • 3
  • 24
  • 47
0

I had the same problem, but non of the answers given here worked for me. The error message I was getting on the import lombok.val imports:

intellij lombok cannot resolve symbol

I'm using IntelliJ "IDEA 2022.3.1 (Community Edition)". Apparently IntelliJ scans the classpath for annotation processing, so adding lombok not for compilation only, but also for runtime worked for me:

Use

implementation 'org.projectlombok:lombok'

instead of

compileOnly 'org.projectlombok:lombok'
Guillermo
  • 764
  • 6
  • 15
0

Similar issue came up during SpringBoot migration to version 3.x.x+. @ConstructorBinding annotation doesn't work with Lombok, it has to be removed

Jacek Sawko
  • 190
  • 2
  • 7
0

In my case, to make it work on some classes defined in the tests using java code in a plain kotlin project (no android) without the kapt plugin, I had to do in my build.gradle.kts:

    dependencies {
        compileOnly("org.projectlombok:lombok:1.18.20")
        annotationProcessor("org.projectlombok:lombok:1.18.20")
        ...
        testCompileOnly("org.projectlombok:lombok:1.18.20")
        testAnnotationProcessor("org.projectlombok:lombok:1.18.20")
    }

Then "Build" -> "Rebuild project" was working.

If you will use the kapt plugin, you should be able to remove the annotationProcessor lines. But I had to deal without kapt in my case.

Geoffrey
  • 69
  • 1
  • 2
  • 5
-3

To get this working, simply install the "Lombok Plugin" for IntelliJ. You don't need to do anything with enabling "Annotation Processors", as some other commentors have suggested. (I've tested this with the latest version of IntelliJ IDEA, currently 2017.1.2). To install the plugin, go to Settings, then Plugins, then click the "Browse repositories" button, then search for "Lombok", and install the Lombok Plugin. You will be prompted to restart IntelliJ. Afterwards, you should be able to compile from IntelliJ, and you won't receive any more error inspections.

user64141
  • 5,141
  • 4
  • 37
  • 34