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

JavaIntellij IdeaLombok

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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

Solution 3 - Java

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

Solution 4 - Java

  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'
     ...
 }

2. Install Lombok plugin for your IDE 3. Check "Enable annotation processing" checkbox in IDE (IntellijIdea), have no idea if there is anything like this for other IDEs like Eclipse.

Solution 5 - Java

in the latest Gradle version you should use annotationProcessor:

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

Solution 6 - Java

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:

Solution 7 - Java

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

Solution 8 - Java

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.

Solution 9 - Java

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.

Solution 10 - Java

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

Solution 11 - Java

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>

Solution 12 - Java

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.

Solution 13 - Java

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.

Solution 14 - Java

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

Solution 15 - Java

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

Solution 16 - Java

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>

Solution 17 - Java

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 an menu option Add library: Gragle: 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)

Solution 18 - Java

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

Solution 19 - Java

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.

Solution 20 - Java

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>

Solution 21 - Java

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.

Solution 22 - Java

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.

Solution 23 - Java

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 .

Solution 24 - Java

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.

Solution 25 - Java

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.

Solution 26 - Java

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

Solution 27 - Java

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

Solution 28 - Java

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

Solution 29 - Java

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

Solution 30 - Java

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.

Solution 31 - Java

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

Solution 32 - Java

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

Solution 33 - Java

For IntelliJ IDEA 2020.1.1 enabling Kotlin plugin fixed this issue.

Solution 34 - Java

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

Solution 35 - Java

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

Solution 36 - Java

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

Solution 37 - Java

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

Solution 38 - Java

  1. add Lombok plugin.
  2. In my case, just maven clean.

Solution 39 - Java

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

Solution 40 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionexpertView Question on Stackoverflow
Solution 1 - Javauser2021572View Answer on Stackoverflow
Solution 2 - JavaCodeShadowView Answer on Stackoverflow
Solution 3 - JavagreperrorView Answer on Stackoverflow
Solution 4 - JavaYevhenii TsybaievView Answer on Stackoverflow
Solution 5 - JavaValeriy K.View Answer on Stackoverflow
Solution 6 - JavaEnrique S. FiliageView Answer on Stackoverflow
Solution 7 - JavaHearenView Answer on Stackoverflow
Solution 8 - JavaSaurabh SahaView Answer on Stackoverflow
Solution 9 - JavaOmri SivanView Answer on Stackoverflow
Solution 10 - Javamt.uuluView Answer on Stackoverflow
Solution 11 - JavaMichel Dambros FigueiredoView Answer on Stackoverflow
Solution 12 - JavamplushnikovView Answer on Stackoverflow
Solution 13 - JavaJasnaRBView Answer on Stackoverflow
Solution 14 - JavaBruceView Answer on Stackoverflow
Solution 15 - Javaso-random-dudeView Answer on Stackoverflow
Solution 16 - JavaShreya MishraView Answer on Stackoverflow
Solution 17 - JavawstView Answer on Stackoverflow
Solution 18 - JavaSrikanth ReddyView Answer on Stackoverflow
Solution 19 - JavaStepan MozyraView Answer on Stackoverflow
Solution 20 - JavaVaibhav KView Answer on Stackoverflow
Solution 21 - JavaTugrulView Answer on Stackoverflow
Solution 22 - JavaSasi Kumar MView Answer on Stackoverflow
Solution 23 - JavaDhiraj SurveView Answer on Stackoverflow
Solution 24 - JavaJohn ChapmanView Answer on Stackoverflow
Solution 25 - JavacybersoftView Answer on Stackoverflow
Solution 26 - JavaKehinde Adedamola ShittuView Answer on Stackoverflow
Solution 27 - JavarealPKView Answer on Stackoverflow
Solution 28 - JavafirstpostcommenterView Answer on Stackoverflow
Solution 29 - JavaMr NobodyView Answer on Stackoverflow
Solution 30 - JavaTGUView Answer on Stackoverflow
Solution 31 - JavaZhongjun 'Mark' JinView Answer on Stackoverflow
Solution 32 - JavaSagiruddin MondalView Answer on Stackoverflow
Solution 33 - JavaVova PerebykivskyiView Answer on Stackoverflow
Solution 34 - JavaBlinkView Answer on Stackoverflow
Solution 35 - JavaS KampenView Answer on Stackoverflow
Solution 36 - Javauser10339671View Answer on Stackoverflow
Solution 37 - JavaDan BitterView Answer on Stackoverflow
Solution 38 - JavahatanoohView Answer on Stackoverflow
Solution 39 - Javabanan3'14View Answer on Stackoverflow
Solution 40 - Javauser64141View Answer on Stackoverflow