Can't compile project when I'm using Lombok under IntelliJ IDEA
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:
- Visit https://projectlombok.org/download
- Download the JAR file into the project lib directory (e.g.,
$HOME/dev/java/project/libs
). - Start the IDE.
- Click File ๐ Settings.
- Expand Build, Execution, Deployment ๐ Compiler ๐ Annotation Processors.
- Ensure Enable annotation processing is checked.
- 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).
- Click Apply.
- Click Plugins.
- Click Marketplace.
- Set search field to:
lombok
- Install Lombok.
- Click OK.
- Restart the IDE if prompted.
- Click File ๐ Project Structure.
- Select Libraries.
- Click the + symbol to add a new project library (or press Alt+Insert).
- Select Java.
- Set the path to:
$HOME/dev/java/project/libs/lombok.jar
- Click OK.
- Select the modules to apply.
- Click OK.
- Optionally, rename
lombok
toProject Lombok 1.18.8
. - 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.
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:
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
- 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'
...
}
- Install Lombok plugin for your IDE
- 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'
Related videos on Youtube
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, 2022Comments
-
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 about 12 yearsErrors 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 over 3 yearsthere is another answer stackoverflow.com/a/63632563/5410940
-
-
expert about 12 yearsIt turned out it fails inside annotation processor. I updated my question with output log.
-
Sanghyun Lee over 8 yearsI also had the same issue. Try change the version of Lombok so that IntelliJ download the dependency again.
-
BeepDog over 8 yearsStill had to do this even with the latest intellij 15.0.2
-
Srikanta about 8 yearsStill 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 almost 8 yearsI 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 almost 8 yearsDon't forget to set annotation processor: lombok.launch.AnnotationProcessorHider$AnnotationProcessor for both maven-compiler-plugin and Idea (Settings -> Compiler -> Annotation Processors)
-
CodeMonkey almost 8 yearsThis 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 almost 8 yearsStill must do in IntelliJ 2016.1.3 :) You have to set the 2 annotation processors. Such a pain when you forget about it!
-
maksimov over 7 yearsThis isn't working for me in 2016.2. Maven web project. The only thing that worked was installing the lombok plugin.
-
Neikius over 7 yearsIdea 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 over 7 yearsStill must do in IntelliJ 2016.3 :)
-
arcuri82 over 7 yearseven by activating in both places, IntelliJ 2016.3.2 still fails to compile with Lombok 1.16.12 :(
-
lreeder almost 7 yearsWorked for me in IDEA 2017.01. Installing Lombok worked for Intellisense, but not for compilation until Annotation Processor was enabled.
-
Hans almost 7 yearsI also had to invalidate the cache and restart before Intellij stopped complaining.
-
TYL over 6 yearsthank you.. I got the same problem. I forgot to install the plugin before I set the Annotation configuration :)
-
Antonio Saco over 6 yearsFor IDEA 2017.3.2, re-installing the Lombok plugin (Uninstall, restart, Install and restart) worked for me.
-
realPK about 6 yearsWhat version of IntelliJ are you using? Also, what JDK version?
-
Carlos Alberto Schneider almost 6 yearsAfter doing it, I still needed to remove and reimport the project as a maven project
-
Beezer about 5 yearsWithout 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 almost 5 yearsIn 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 over 4 yearsthis, this, and a thousand times this. Thank you, I was stuck for one hour
-
Stevers over 4 yearsCame here for the 2019 version update... thank you so much.
-
Gryk over 4 yearsin 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 over 4 yearsyep, you are right, we should check the build config first, then IDE setting. thanks a heap!
-
thenakulchawla over 4 yearsI don't see Default Settings in Other Settings in IntelliJ. Are these still present. I am using the Ultimate edition - version11.03
-
doctorram almost 4 yearsThis is the only thing that actually worked! Why it has only 13 likes?!
-
0x01Brain almost 4 yearsDid 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 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 almost 4 yearsnever 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 over 3 yearsI had to add
requires org.slf4j;
to mole-info.java also -
Urosh T. over 3 yearsThanks, worked like a charm for 2020.3 CE!
-
Devon about 3 yearsThis solution should be much more upvoted. I was investigating this for hours, and this was the only thing that worked.
-
Stevers about 3 yearsGod i forgot Gradle added annotationProcessor in newer versions. Thank you for your answer.
-
vikas tiwari over 2 yearsAfter going throgh so many solutions , this worked for me. After adding "annotationProcessor" , everything started working fine.
-
Caio Santos over 2 yearsIt 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 over 2 yearsThis is the correct answer. I didn't have 'annotationProcessor' defined in my build.gradle dependencies.
-
pepe450 over 2 yearsNeeded to do this on 2021.1.2
-
KaraKaplanKhan about 2 years@Gryk after adding your suggestion it worked in my application. Thank you.
-
Duy Tran almost 2 yearsThank you, this is best answer for saving me hours.
-
Orlando Alfonso almost 2 yearsAwesome, yep the problem was on my gradle dependencies, thanks so much