This question already has answers here:
Can't compile project when I'm using Lombok under IntelliJ IDEA
(43 answers)
Closed 3 years ago.
I've installed the plugin for intellij idea(lombok-plugin-0.8.6-13).
Added lombok.jar into classpath
I can find getters and setters in the window of structure. And Intellij shows no error.
Setting - Lombok plugin - Verified Intellij configuration for lombok, it shows that "configuration of IntelliJ seems to be ok".
It seems everything is OK. But when I compile a test, errors come: can not find the methods getXXX and setXXX.
I opened the .class file with IntelliJ and find out that there is no setXXX and getXXX methods.
Could somebody tell me why?
plugin:lombok-plugin-0.8.6-13
lombok.jar:1.14.0
idea:13.0.2 for linux
jdk:1.7.0_21
In order to solve the problem set:
Preferences (Ctrl + Alt + S)
Build, Execution, Deployment
Compiler
Annotation Processors
Enable annotation processing
Make sure you have the Lombok plugin for IntelliJ installed!
Preferences -> Plugins
Search for "Lombok Plugin"
Click Browse repositories...
Choose Lombok Plugin
Install
Restart IntelliJ
If you're using Eclipse compiler with lombok, this setup finally worked for me:
IDEA 14.1
Lombok plugin
... / Compiler / Java Compiler > Use Compiler: Eclipse
... / Compiler / Annotation Processors > Enable annotation processing: checked (default configuration)
... / Compiler > Additional build process VM options:(Shared build process VM options) -javaagent:lombok.jar
The most important part is the last one, mine looks like following:
Plugin is needed for IntelliJ editor to recognize getters and setters, javaagent is needed for eclipse compiler to compile with lombok.
If you're using Intellij on Mac, this setup finally worked for me.
Installations: Intellij
Go to Preferences, search for Plugins.
Type "Lombok" in the plugin search box. Lombok is a non-bundled plugin, so it won't show at first.
Click "Browse" to search for non-bundled plugins
The "Lombok Plugin" should show up. Select it.
Click the green "Install" button.
Click the "Restart Intellij IDEA" button.
Settings:
Enable Annotation processor
Go to Preferences -> Build, Execution,Deployment -->Preferences -> Compiler -> Annotation Processors
File -> Other Settings -> Default Settings -> Compiler -> Annotation Processors
Check if Lombok plugin is enabled
IntelliJ IDEA-> Preferences -> Other Settings -> Lombok plugin -> Enable Lombok
Add Lombok jar in Global Libraries and project dependencies.
File --> Project Structure --> Global libraries (Add lombok.jar)
File --> Project Structure --> Project Settings --> Modules --> Dependencies Tab = check lombok
Restart Intellij
I followed this procedure to get ride of a similar/same error.
mvn idea:clean
mvn idea:idea
After that I could build both from the IDE intellij and from command line.
For me, both lombok plugin and annotation processing enable needed, no else. No need to Use Eclipse and additional -javaagent:lombok.jar options.
Idea 14.1.3, build 141.1010
Lombok plugin[Preference->plugins->browse repositories->search 'lombok'->install and restart idea.
Preference ->search 'annotation'->enter annotation processor ->enable annotation processing.
After spending far too long troubleshooting this, I found a simple workaround which ensures IntelliJ processes Lombok annotations correctly during builds.
The gradle-lombok plugin is not necessary for this workaround. Your build.gradle only requires the following:
dependencies {
compileOnly("org.projectlombok:lombok:1.16.18")
}
The workaround is to turn on the following IntelliJ setting:
Open IntelliJ preferences/settings.
Navigate to Build, Execute, Deployment > Build Tools > Gradle > Runner
Check the box labeled Delegate IDE build/run actions to gradle
Benefits of this workaround compared to other solutions on this page:
No annotation processing necessary!
Able to use the Java compiler of your choice (no Eclipse compiler necessary)
No use of buggy gradle-lombok plugin (although perhaps someone else can solve this)
No VM options necessary
No hard-coded paths to lombok jar
One downside is that IntelliJ will no longer use its own test runner. Instead, tests are always run through Gradle.
IDEA 2016.1:
Install lombok plugin
Settings -> Compiler -> Annotation Processors -> Enable annotation processing: checked (default configuration)
Settings -> Compiler -> Annotation Processors -> Annotation Processors add "lombok.launch.AnnotationProcessorHider$AnnotationProcessor"
Also if you are using maven add to maven-compiler-plugin configuration -> annotationProcessors -> annotationProcessor: lombok.launch.AnnotationProcessorHider$AnnotationProcessor
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.plugin.compiler.version}</version>
<configuration>
<compilerVersion>${java.version}</compilerVersion>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessors>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
Make sure these two requirements are satisfied:
Enable annotation processing,
Preferences > Build, Execution, Deployment > Compiler > Annotation Processors > Enable annotation processing
Lombok plugin is installed and enabled for your project.
None of the advanced answers to this question resolved the problem for me.
I managed to solve the problem by adding a dependencie to lombok in the pom.xml file, i.e. :
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
</dependency>
I am using IntelliJ 2016.3.14 with maven-3.3.9
Hope my answer will be helpful for you
On Itellij 15 CE, it's enough to just install Lombok Plugin (no additional configuration required).
I am unable to get this working with the javac compiler, and I get the same error.
Error:(9, 14) java: package lombok does not exist
I have enabled annotation processor, and have also tried rebuilding the project, invalidate cache/restart. Doesn't help.
I did however get it to work partially with eclipse compiler. I say partial because although the build passes successfully, the editor still complains about "Cannot resolve symbol".
Idea - 15.04 community edition
Lombok - 1.16.6
Lombok plugin (https://github.com/mplushnikov/lombok-intellij-plugin) - 0.9.8
JDK - 1.8.0_51
Update:
Ok, I finally got this working. Mine was a gradle project, and lombok was configured as a custom "provided" configuration. Worked fine after adding this in build.gradle
idea {
module {
scopes.PROVIDED.plus += [configurations.provided]
}
}
So, 3 steps
Install Lombok plugin from File->Settings->Plugins
Enable Annotation Processor (javac compiler works too)
Ensure that you have build.gradle or pom.xml updated for idea if you are adding lombok as a custom config.
Related
When running a JUnit test, using IntelliJ IDEA, I get
How can I correct this?
Using SDK 1.7
Module language level is 1.7
Maven build works fine. (That's why I believe this in IDEA configuration issue)
Most likely you have incorrect compiler options imported from Maven here:
Also check project and module bytecode (target) version settings outlined on the screenshot.
Other places where the source language level is configured:
Project Structure | Project
Project Structure | Modules (check every module) | Sources
Maven default language level is 1.5 (5.0), you will see this version as the Module language level on the screenshot above.
This can be changed using maven-compiler-plugin configuration inside pom.xml:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
or
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
IntelliJ IDEA will respect this setting after you Reimport the Maven project in the Maven Projects tool window:
IntelliJ 15, 2016 & 2017
Similar to that discussed below for IntelliJ 13 & 14, but with an extra level in the Settings/Preferences panel: Settings > Build, Execution, Deployment > Compiler > Java Compiler.
IntelliJ 13 & 14
In IntelliJ 13 and 14, check the Settings > Compiler > Java Compiler UI to ensure you're not targeting a different bytecode version in your module.
In IntelliJ IDEA 14.1 the "Target bytecode version" is in a different place.
The following change worked for me:
File > Settings... > Build, Execution, Deployment > Compiler > Java Compiler : change Target bytecode version from 1.5 to 1.8
Have you looked at your build configuration it should like that if you use maven 3 and JDK 7
<build>
<finalName>SpringApp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
</plugins>
...
</build>
I ran into this and the fix was to go to Project Settings > Modules > click on the particular module > Dependencies tab. I noticed the Module SDK was still set on 1.6, I changed it to 1.7 and it worked.
I've found required options ('target bytecode version') in settings > compiler > java compiler in my case (intelij idea 12.1.3)
Modify the compiler setting file of the project in the following path and change the 'target' to 1.7:
/project/.idea/compiler.xml
<bytecodeTargetLevel>
<module name="project-name" target="1.7" />
</bytecodeTargetLevel>
I resolved it by setting the field blank:
Settings > Compiler > Java Compiler > Project bytecode version
Than IntelliJ uses the JDK default version.
From one moment to the other I also got this error without a clear reason. I changed all kinds of settings on the compiler/module etc. But in the end I just recreated the IntelliJ project by reimporting the Maven project and the issue was solved. I think this is a bug.
IntelliJ 12 129.961
I've hit this after just minor upgrade from IntelliJ IDEA 14 to v14.1.
For me changing an edit of top/parent pom helped and then clicked re-import Maven (if it is not automatic).
But it maybe just enough to Right Click on module(s)/aggregated/parent module and Maven -> Reimport.
I resolved bellow method
File >> Project Structure >> Project >> Project Language Level
--> do set proper version (ex: 1.5)
check
.idea/misc.xml
sometimes you need to change languageLevel="JDK_1_X" attribute manually
If it is a Gradle project, in your build.gradle file, search for following settings:
sourceCompatibility = "xx"
targetCompatibility = "xx"
For all subrpojects, in your root build.gradle file, you may put:
subprojects { project ->
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
Although you can manually set language levels in Idea > Settings, if it is a Gradle project, Idea automatically synchronizes module .iml files from Gradle settings ( tested with Idea 15+). So all your manual changes are overriden when gradle is refreshed.
Based on Gradle documentation, if these are not set, then current JVM configuration is used.
I found another way to run into this error. You can get this if you have been re-organizing your directory structure, and one of your poms is pointing to the old parent which no-longer configures javac (because that configuration was moved to a middle level). If this happens the top level defaults to 1.5 and the misbehaving lower level pom inherits it.
So another thing to check when you see this error is that your pom structure is matching your directory structure properly.
If Maven build works fine, try to synchronizing structure of Maven and IntelliJ IDEA projects.
In the Maven tool window, click refresh button . On pressing this button, IntelliJ IDEA parses the project structure in the Maven tool window.
Note that this might not help if you're using EAP build, since Maven synchronization feature may be broken sometimes.
If all the previous solutions haven't worked for you (which was my case), you can delete intellij config files:
project_directory/.idea/compiler.xml
project_directory/.idea/encodings.xml
project_directory/.idea/misc.xml
project_directory/.idea/modules.xml
project_directory/.idea/vcs.xml
project_directory/.idea/workspace.xml
etc.
Intellij will regenerate new ones later.
However, BE CAREFUL, this will also delete all intellij configuration made on the projet (i.e: configuration of debug mode, ...)
You need to change Java compiler version in in build config.
Make sure right depency is selected.
File > Project Structure
Select your project and navigate to Dependencies tab. Select right dependancy from dropdown or create new.
I use IntelliJ IDEA as my development environment, and Maven for dependency management. I frequently build my project structure (directories, poms, etc) outside of IDEA and then import the project into IDEA using Import project from external model. This works great, except that in my poms I specify that the maven-compiler-plugin should use JDK 1.6, and when I import, IDEA informs me that the Language Level Changed and that Language level changes will take effect on project reload, and then prompts to reload the project. This is annoying because I always use the same JDK version.
How do I change the default JDK that IntelliJ IDEA uses, so that I don't have to reload my project every time I import a new project?
This setting is changed in the "Structure for New Projects" dialog. Navigate to "File" -> "New Projects Setup" -> "Structure..."
Next, modify the "Project SDK" and "Project Language Level" as appropriate.
Previous versions of IntelliJ IDEA had this setting in "File" -> "Other Settings" -> "Default Project Structure...".
IntelliJ IDEA 12 had this setting in "Template Project Structure..." instead of "Default Project Structure..."
Download and unpack a JDK archive file (.tar.gz) and add it as a SDK in the 'Project Structure' dialog box ( Ctrl+Alt+Shift+S )
click on the gif to enlarge
Also make sure to set an appropriate 'Project language level'. I forgot to do that when creating the GIF.
Project Structure > Project > Project language level
For Java 8 set it to 8, for Java 9 set it to 9, and so on.
I am using IntelliJ IDEA 14.0.3, and I also have same question. Choose menu File \ Other Settings \ Default Project Structure...
Choose Project tab, section Project language level, choose level from dropdown list, this setting is default for all new project.
I have found out that in recent versions of IntelliJ IDEA requires Java 1.8 but is not configured by default.
We can change the path or configure from Project Settings > Project > Project SDK
here we can edit or add the JDK´s path.
(in my case the path is located in C:\Program Files\Java\jdk1.8.0_102)
Change JDK version to 1.8
Language level File -> project Structure -> Modules -> Sources -> Language level -> 8-Lambdas, type annotations etc.
Project SDk File -> project Structure -> Project 1.8
Java compiler File -> Settings -> Build, Executions, Deployment -> Compiler -> Java compiler
One other place worth checking: Look in the pom.xml for your project, if you are using Maven compiler plugin, at the source/target config and make sure it is the desired version of Java. I found that I had 1.7 in the following; I changed it to 1.8 and then everything compiled correctly in IntelliJ.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
The above responses were very useful, but after all settings, the project was running with the wrong version. Finally, I noticed that it can be also configured in the Dependencies window.
Idea 2018.1.3 File -> Project Structure -> Modules -> Sources and Dependencies.
To change the JDK version of the Intellij-IDE himself:
Start the IDE -> Help -> Find Action
than type:
Switch Boot JDK
or (depend on your version)
Switch IDE boot JDK
For latest version intellij, to set default jdk/sdk for new projects go to
Configure->Structure for New Projects -> Project Settings -> Project SDK
I am using IntelliJ 2020.3.1 and the File > Other Settings... menu option has disappeared. I went to Settings in the usual way and searched for "jdk". Under Build, Execution, Deployment > Build Tools > Maven > Importing I found the the setting that will solve my specific issue:
JDK for importer.
On my linux machine I use a script like this:
export IDEA_JDK=/opt/jdk14
/idea-IC/bin/idea.sh
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.
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 to Project 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).
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:
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
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.
in the latest Gradle version you should use annotationProcessor:
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
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:
https://github.com/rzwitserloot/lombok/issues/2592#issuecomment-705449860
https://youtrack.jetbrains.com/issue/IDEA-250718#focus=Comments-27-4418347.0-0
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 :)
If 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.
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>
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.
there is a plugin for intellij. see here: https://projectlombok.org/download.html
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.
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、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".
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
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>
If you already installed it, then for refresh just deselect and select Enable annotation in Intellij Settings.
I have faced this problem after updating the IDEA to 2018.3. I had to update all the existing plugin
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.
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>
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
For IntelliJ IDEA 2020.1.1 enabling Kotlin plugin fixed this issue.
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.
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.
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
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 .
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
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)
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.
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.
I am using IntelliJ IDEA 2018.2.5 (Community Edition). Here are the complete details.
Build #IC-182.4892.20, built on October 16, 2018
JRE: 1.8.0_152-release-1248-b19 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
I have followed all the suggested solutions in so many different answers in SO. but nothing worked for me.
Here are the screenshots of required setting that needs to be done for lombok package.
lombok jar is available in external libraries.
I still get the error while compiling the application.
Project Library:
I had the same problem, after change git branch in intellij.
The solution is:
on project panel (left side) right click on pom.xml file
click on "Add as Maven Project"
In my case, I forgot the test dependency:
testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
Gradle 4.10, java1.8, Intellij Idea 2018.3.2
Try to setup the scope directly. Example for maven:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>compile</scope>
</dependency>
In order for intelliJ to be able to read lombok at compile time, you would have to update annotation processor settings in the IDE and then add the plugin for lombok.
Please refer to this link for details about how to do the above said changes.
I met exactly the same issue, but couldn't let it go after tried all solutions I could found in stackoverflow.
Eventually, I fixed it, by changing Preferences - Build, Execution, deployment > Build Tools > Gradle:
Build and run using: Gradle (Default) // it was Intellij IDEA
Run tests using: Gradle (Default) // it was Intellij IDEA
Gradle JVM: 11 // use 8 and above
Not sure if this is the right answer, but any of you have this issue can try. I believe it's just the IntelliJ setting caused problem.
Check out this link: https://projectlombok.org/setup/gradle
I had the same problem and resolved it after adding lombok dependencies in build.gradle
for me:
I downmoad "lombok.jar" for origine site "https://projectlombok.org/download".
in intellij IDE, File => Preject Structure => Librairies.
click to button "+" to add librairies => java => file "lombok.jar"
that's works for me
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.
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 to Project 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).
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:
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
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.
in the latest Gradle version you should use annotationProcessor:
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
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:
https://github.com/rzwitserloot/lombok/issues/2592#issuecomment-705449860
https://youtrack.jetbrains.com/issue/IDEA-250718#focus=Comments-27-4418347.0-0
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 :)
If 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.
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>
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.
there is a plugin for intellij. see here: https://projectlombok.org/download.html
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.
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、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".
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
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>
If you already installed it, then for refresh just deselect and select Enable annotation in Intellij Settings.
I have faced this problem after updating the IDEA to 2018.3. I had to update all the existing plugin
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.
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>
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
For IntelliJ IDEA 2020.1.1 enabling Kotlin plugin fixed this issue.
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.
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.
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
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 .
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
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)
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.
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.