240
votes

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.

30
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

30 Answers

466
votes

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

74
votes

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

69
votes

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

41
votes
  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.
16
votes

in the latest Gradle version you should use annotationProcessor:

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

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

12
votes

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:

9
votes

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.

7
votes

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.

7
votes

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

5
votes

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.

4
votes

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>
3
votes

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.

3
votes

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

3
votes

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

3
votes

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>
1
votes

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)

1
votes

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

1
votes

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.

1
votes

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>
1
votes

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.

1
votes

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.

0
votes

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.

0
votes

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.

0
votes

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
votes

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

0
votes

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
0
votes

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

0
votes

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.

0
votes

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