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

271,076

Solution 1

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

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

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

  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.

Solution 5

in the latest Gradle version you should use annotationProcessor:

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
Share:
271,076

Related videos on Youtube

expert
Author by

expert

My interests: scala kotlin java deep-learning machine-learning reactive-programming scala-cats project-reactor scalability reverse-engineering peer-to-peer. Back in 2005 I created Morpheus, the most popular file sharing application in North America. I also designed and built Dell Digital Delivery (similar to Steam for non-games) which is installed on every Dell PC world-wide and worked on improving architecture of Fivetran. Currently I'm building super-fast hybrid (batching/realtime) data integration pipeline at bitparticles.

Updated on January 21, 2022

Comments

  • expert
    expert over 2 years

    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.

    • Nowaker
      Nowaker about 12 years
      Errors appear even without the plugin. I am not able to run tests of a project if Lombok is in my pom.xml dependencies.
    • Error Hunter
      Error Hunter over 3 years
      there is another answer stackoverflow.com/a/63632563/5410940
  • expert
    expert about 12 years
    It turned out it fails inside annotation processor. I updated my question with output log.
  • Sanghyun Lee
    Sanghyun Lee over 8 years
    I also had the same issue. Try change the version of Lombok so that IntelliJ download the dependency again.
  • BeepDog
    BeepDog over 8 years
    Still had to do this even with the latest intellij 15.0.2
  • Srikanta
    Srikanta about 8 years
    Still present in 15.0.4. I also had to update the Lambok version to the latest and change the Java compiler to JAVAC. Then do a rebuild of the project
  • Alex
    Alex almost 8 years
    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.
  • Jan Kubovy
    Jan Kubovy almost 8 years
    Don't forget to set annotation processor: lombok.launch.AnnotationProcessorHider$AnnotationProcessor for both maven-compiler-plugin and Idea (Settings -> Compiler -> Annotation Processors)
  • CodeMonkey
    CodeMonkey almost 8 years
    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.
  • Ray Hunter
    Ray Hunter almost 8 years
    Still must do in IntelliJ 2016.1.3 :) You have to set the 2 annotation processors. Such a pain when you forget about it!
  • maksimov
    maksimov over 7 years
    This isn't working for me in 2016.2. Maven web project. The only thing that worked was installing the lombok plugin.
  • Neikius
    Neikius over 7 years
    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?
  • Sukesh Kotian
    Sukesh Kotian over 7 years
    Still must do in IntelliJ 2016.3 :)
  • arcuri82
    arcuri82 over 7 years
    even by activating in both places, IntelliJ 2016.3.2 still fails to compile with Lombok 1.16.12 :(
  • lreeder
    lreeder almost 7 years
    Worked for me in IDEA 2017.01. Installing Lombok worked for Intellisense, but not for compilation until Annotation Processor was enabled.
  • Hans
    Hans almost 7 years
    I also had to invalidate the cache and restart before Intellij stopped complaining.
  • TYL
    TYL over 6 years
    thank you.. I got the same problem. I forgot to install the plugin before I set the Annotation configuration :)
  • Antonio Saco
    Antonio Saco over 6 years
    For IDEA 2017.3.2, re-installing the Lombok plugin (Uninstall, restart, Install and restart) worked for me.
  • realPK
    realPK about 6 years
    What version of IntelliJ are you using? Also, what JDK version?
  • Carlos Alberto Schneider
    Carlos Alberto Schneider almost 6 years
    After doing it, I still needed to remove and reimport the project as a maven project
  • Beezer
    Beezer about 5 years
    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.
  • user5365075
    user5365075 almost 5 years
    In my case, I wasn't seeing a warning message before the errors, saying that plugin Lombok had been disabled because of delegating issues. Turned out Idea was trying to use Java 11 to compile. After downgrading to Java 1.8, everything worked fine.
  • ch1ll
    ch1ll over 4 years
    this, this, and a thousand times this. Thank you, I was stuck for one hour
  • Stevers
    Stevers over 4 years
    Came here for the 2019 version update... thank you so much.
  • Gryk
    Gryk over 4 years
    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")
  • Eric Tan
    Eric Tan over 4 years
    yep, you are right, we should check the build config first, then IDE setting. thanks a heap!
  • thenakulchawla
    thenakulchawla over 4 years
    I don't see Default Settings in Other Settings in IntelliJ. Are these still present. I am using the Ultimate edition - version11.03
  • doctorram
    doctorram almost 4 years
    This is the only thing that actually worked! Why it has only 13 likes?!
  • 0x01Brain
    0x01Brain almost 4 years
    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
  • Hearen
    Hearen almost 4 years
    @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 ;)
  • 0x01Brain
    0x01Brain almost 4 years
    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.
  • Pavlo Zvarych
    Pavlo Zvarych over 3 years
    I had to add requires org.slf4j; to mole-info.java also
  • Urosh T.
    Urosh T. over 3 years
    Thanks, worked like a charm for 2020.3 CE!
  • Devon
    Devon about 3 years
    This solution should be much more upvoted. I was investigating this for hours, and this was the only thing that worked.
  • Stevers
    Stevers about 3 years
    God i forgot Gradle added annotationProcessor in newer versions. Thank you for your answer.
  • vikas tiwari
    vikas tiwari over 2 years
    After going throgh so many solutions , this worked for me. After adding "annotationProcessor" , everything started working fine.
  • Caio Santos
    Caio Santos over 2 years
    It worked for me. I use Kotlin DSL and my code is like this:dependencies { compileOnly("org.projectlombok:lombok:1.18.8") annotationProcessor("org.projectlombok:lombok:1.18.8") ... }
  • Elyasaf755
    Elyasaf755 over 2 years
    This is the correct answer. I didn't have 'annotationProcessor' defined in my build.gradle dependencies.
  • pepe450
    pepe450 over 2 years
    Needed to do this on 2021.1.2
  • KaraKaplanKhan
    KaraKaplanKhan about 2 years
    @Gryk after adding your suggestion it worked in my application. Thank you.
  • Duy Tran
    Duy Tran almost 2 years
    Thank you, this is best answer for saving me hours.
  • Orlando Alfonso
    Orlando Alfonso almost 2 years
    Awesome, yep the problem was on my gradle dependencies, thanks so much