Reputation: 30145
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.
Upvotes: 291
Views: 418030
Reputation: 5064
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?.
Upvotes: 2
Reputation: 31
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>
Upvotes: 2
Reputation: 18030
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
Upvotes: 3
Reputation: 774
I solved the problem by directing Annotation Processors to the correct jar of lombok.
Build, Execution, Deployment -> Compiler -> Annotation Processors ->
Or, choose the correct jar manually. In your .m2 folder, there are different lombok jars for your project, and if you don't specify a version for this dependency, Intellij picks up a wrong one (unknown). Change this to the latest one manually, like .m2\repository\org\projectlombok\lombok<aValidVersion>
Upvotes: 1
Reputation: 21
another thing that might help is to go into .idea folder, then open compiler.xml. You should something like this:
make sure the path is correct and lombok version matches the one in your pom.xml.
Upvotes: 0
Reputation: 156
I faced the same problem. We need to add the annotation processor, other answer might be right with configuring it via IDE, we can also add it in build.gradle as
annotationProcessor 'org.projectlombok:lombok'
Sample Gradle File
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
Upvotes: 0
Reputation: 51
I had the same issue, in my case, I created a util class in the test package and Lombok simply didn't work. I guess you have to specifically define which packages have to run in the configuration.
But I just moved my util class to the main src folder and it worked.
Upvotes: 0
Reputation: 5064
For IntelliJ 2023.1.3, I had to close IntelliJ, remove all *.iml
files, all .idea
folders, rename the project folder, add lombok dependency to pom, create a new project in intellij, import a module from sources, enable annotation processing and then it finally understood what I want.
Upvotes: 0
Reputation: 494
In my case, to make it work on some classes defined in the tests using java code in a plain kotlin project (no android) without the kapt
plugin, I had to do in my build.gradle.kts
:
dependencies {
compileOnly("org.projectlombok:lombok:1.18.20")
annotationProcessor("org.projectlombok:lombok:1.18.20")
...
testCompileOnly("org.projectlombok:lombok:1.18.20")
testAnnotationProcessor("org.projectlombok:lombok:1.18.20")
}
Then "Build" -> "Rebuild project" was working.
If you will use the kapt
plugin, you should be able to remove the annotationProcessor
lines. But I had to deal without kapt
in my case.
Upvotes: 0
Reputation: 348
Similar issue came up during SpringBoot migration to version 3.x.x+.
@ConstructorBinding
annotation doesn't work with Lombok, it has to be removed
Upvotes: 0
Reputation: 791
I had the same problem, but non of the answers given here worked for me. The error message I was getting on the import lombok.val
imports:
intellij lombok cannot resolve symbol
I'm using IntelliJ "IDEA 2022.3.1 (Community Edition)". Apparently IntelliJ scans the classpath for annotation processing, so adding lombok not for compilation only, but also for runtime worked for me:
Use
implementation 'org.projectlombok:lombok'
instead of
compileOnly 'org.projectlombok:lombok'
Upvotes: 0
Reputation: 2494
If you already installed it, then for refresh just deselect and select Enable annotation
in Intellij Settings.
Upvotes: 2
Reputation: 4338
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 a menu option Add library: Gradle: 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)
Upvotes: 1
Reputation: 4536
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
Upvotes: 2
Reputation: 392
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 .
Upvotes: 1
Reputation: 259
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
Upvotes: 0
Reputation: 69
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.
Upvotes: 0
Reputation: 5282
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:
$HOME/dev/java/project/libs
).lombok
$HOME/dev/java/project/libs/lombok.jar
lombok
to Project Lombok 1.18.8
.The project can now import from the lombok
package and use Project Lombok annotations (e.g., lombok.Setter
and lombok.Getter
).
Upvotes: 525
Reputation: 41
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
Upvotes: 1
Reputation: 2630
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.
Upvotes: 1
Reputation: 810
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:
Upvotes: 27
Reputation: 1554
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
Upvotes: 0
Reputation: 1808
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.
Upvotes: 2
Reputation: 623
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>
Upvotes: 19
Reputation: 747
For IntelliJ IDEA 2020.1.1 enabling Kotlin plugin fixed this issue.
Upvotes: 1
Reputation: 5797
For me what worked:
Upvotes: 1
Reputation: 51
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>
Upvotes: 2
Reputation: 267
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.
Upvotes: 1
Reputation: 2904
in the latest Gradle version you should use annotationProcessor:
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
Upvotes: 38