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 Kotlin. Do not use Lombok.
-
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– Nowaker2012年02月26日 21:57:26 +00:00Commented Feb 26, 2012 at 21:57
-
there is another answer stackoverflow.com/a/63632563/5410940Error Hunter– Error Hunter2020年08月28日 11:11:43 +00:00Commented Aug 28, 2020 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 -stackoverflow.com/a/65188047/529659jomofrodo– jomofrodo2022年08月31日 22:04:18 +00:00Commented Aug 31, 2022 at 22:04
-
This solution solved my problem: stackoverflow.com/a/76157466MHSaffari– MHSaffari2024年09月29日 06:19:12 +00:00Commented Sep 29, 2024 at 6:19
-
"Don't use Lombok" - good advice. There's the answer!duffymo– duffymo2025年01月04日 12:21:05 +00:00Commented Jan 4 at 12:21
52 Answers 52
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
lomboktoProject 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).
16 Comments
build.gradle: annotationProcessor "org.projectlombok:lombok:1.18.8" testAnnotationProcessor("org.projectlombok:lombok:1.18.8")- 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.
9 Comments
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:
1 Comment
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
5 Comments
in the latest Gradle version you should use annotationProcessor:
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
1 Comment
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 Option1.
I didn't need to use the -javaagent approach, neither setup the classpath.
1. Go to: File | Settings | Build, Execution, Deployment | Compiler | "Shared build process VM options" field
References:
1 Comment
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 Comments
requires org.slf4j; to mole-info.java alsoReload project from the menu after having added this.Just for reference using IntelliJ 2018.3, I solved this issue (using @Data annotation to insert getter/setter) following the three steps:
- File -> Settings -> Build, Execution, Deployment -> Annotation Processors -> Enable Annotation Processing;
Do remember to Apply the change.
- Install plugin lombok in the same setting dialog;
- It seems good enough for now, it requires to restart IntelliJ and then rebuild your project.
Best wishes :)
3 Comments
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 processingIf you have checked both these steps as follows
- Enable annotations : this is a check done in IntelliJ preferences.
- 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.
Comments
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.
Comments
there is a plugin for intellij. see here: https://projectlombok.org/download.html
2 Comments
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.
1 Comment
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.
1 Comment
Please make sure, you have added the ${lombok.version} in pom.xml or just replace/paste this snippet in pluggins
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
1 Comment
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 Comment
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".
1 Comment
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
Comments
IDEA set wrong jar processor path in this settings for multi-module maven. Correct it or set "Obtain processors from classpath" - the simplest working option
1 Comment
C:\Users\nshln\.m2\repository\org\projectlombok\lombok\unknown\lombok-unknown.jar ...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>
Comments
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.
Comments
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
Comments
If you already installed it, then for refresh just deselect and select Enable annotation in Intellij Settings.
Comments
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.
it might also be a mess with Java version, Spring, and lombok for higher versions thereof, take a look Compilation error after upgrading to JDK 21 - "NoSuchFieldError: JCImport does not have member field JCTree qualid".
Those are the version I reverted to struggling with Java 23:
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.4</version>
<java.version>17</java.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<mapstruct-processor.version>0.2.0</mapstruct-processor.version>
<lombok.version>1.18.30</lombok.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
and it worked. See also this one How to configure Lombok with maven-compiler-plugin?.
Comments
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
Comments
I have faced this problem after updating the IDEA to 2018.3. I had to update all the existing plugin
Comments
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.
Comments
For me what worked:
- I uninstalled the installed the Lombok plugin freshly
- I ticked "Enable Annotation Plugin"
- I selected "Obtain processor from the project classpath" in the same page
Comments
For IntelliJ IDEA 2020年1月1日 enabling Kotlin plugin fixed this issue.
Comments
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.
Comments
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