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 went to the Preference of Eclipse and changed the default JRE to the Java SE 8, and also changed the Compiler settings of Eclipse to be 1.8 JDK compliance. I even removed the other JREs.
However, when I import a project, as you can see from the Project Explorer, the project name is "SpringService", somehow the JRE System Library is JavaSE-1.6 and they are still using 1.6 as default!
Can anyone tell me what I did wrong? Otherwise every new project I have to manually go to the properties and change it manually! Hate it!
This post might be relevant to enter link description here SO question.
When you set your Installed JREs preference, you want to select the root directory of a full Java Development Kit installation, not just a bare JRE installation. Eclipse needs access to the supporting libraries that are bundled with a full JDK, but absent from a base JRE install.
Also, if you are importing a project, do you mean that you are importing an existing, pre-configured Eclipse project? Or just the directory structure that contains the source code? If you are importing an existing Eclipse project, it may have already been set up with project-specific settings (it's hard to give advice with being able to poke around in the settings).
Check the plugin section in the pom.xml to see if it contains the following entry.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
This will overwrite the default preference. A lot of maven project archetype uses 1.6. Just change them to 1.8 and do a Maven->Update Project.
U can you 'Build Path' on the project ,then remove the jre1.6, add the user libiary .
We have a Maven based Android build, and we just made the switch from JDK 6 to 7.
This came with its share of IntelliJ problems though. What happens is that every time it detects a change in the POM, and reimports/refreshes the project, it returns to selecting the old "Module SDK", the one that's configured to use Java 6:
Even if I manually delete these SDKs from the "Platform Settings" dialog, they keep reappearing as "Maven Android API 19 Platform (N)" where N is the number used to disambiguate it from all the other (identical) SDKs.
I should mention that we do specify in the POM that Java 7 is targeted. I tried to set both the compiler plugin language level, and the maven.compiler.* properties (not sure if that accomplishes the same thing or not), without luck:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
shouldn't IntelliJ pick that up and always configure the project to use a Java 7 SDK? Am I missing something?
I noticed that the problem disappears when I remove any references to 1.6 SDKs entirely in IntelliJ. Not surprising I guess, but also not viable since I have other projects that still rely on the presence of a Java 6 SDK.
I encountered a very similar issue with Maven projects I'd created using IntelliJ (version 14.x in my case). I'd configured IntelliJ to use JDK 8 in the Project Settings but the IDE continued to highlight issues in my code (e.g. complaining about the usage of #Override).
It turns out that the Maven Settings take precedence here, which in my case defaulted to JDK 1.5 (hence the IDE redlines). Changing the settings here does resolve the issue, but only temporarily because they revert back whenever the Maven projects are reimported, or when IntelliJ is restarted.
The permanent fix is to explicitly declared the JDK version in your Maven pom file, as explained in these items.
stop IntelliJ IDEA to switch java language level everytime the pom is reloaded (or change the default project language level) by #vikingsteve
IDEA: javac: source release 1.7 requires target release 1.7 by #bacchus
Here's what they've said you need to add to your pom.xml file.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
These settings get reflected in the Maven Settings in the IDE and resolved the issue for me.
It will pick up the jdk that you choose in project structure please change it there.
File > project structure > project setting > project > project sdk choose 1.7.
If 1.7 is not present go to
File > project structure > Platform setting > SDKs addd 1.7 there.
It's also important to note that you need to change the runner (jdk level) of your maven.
Maven > Runner > JRE
I have the problem mentioned in the title. You could say that this thread duplicates another one: How do I turn off error validation for annotations in IntelliJ IDEA?
But the solution given there doesn't work. They say that I need to take the following action:
In the Project Structure | Project dialog, change the Project language Level to 6.0 - #Override in interfaces.
However, the Project language Level is 6.0 at the moment, but I still see the error.
Vic, here is the window and there is no JVM version right under Language level (unfortunately I can't post images because I have 10 reputation)
If your project has multiple modules, also check that every module uses language level 6 or above, or use the project's language level (see Project Settings > Modules > xxx > Language level).
You may need to reload your project once it is modified.
At your module/project, Right click to see context menu:
Choose Open Module Settings or press F4. In setting windows:
Set value for Choose Language level section.
You also should check Project language level by this way: press Ctrl+Alt+Shift+S
A simpler solution - inline
Put the caret on the #Override word and move the caret on the left side until the red bulb icon will appear. Then click on it.
Click on Set language level to 6 - Override in interfaces
The method above is an alternative to the following approach:
Go to File > Project Structure... or press Ctrl+Alt+Shift+S
Go to Project Settings > Modules > Sources > Language level and choose any level that is 6 or greater than 6.
If you are using maven, add maven compiler plugin to the project's pom.xml file.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
This solved the issue for me.
There's also a language level for every module. Please check your module settings in the Project Structure.
I ran into this problem for the first time while using a multi module maven project. As other answers / IDE suggested, we need to set the language level.
Rather than changing the setting of IDE, to make the project IDE agnostic, I update the parent pom with below properties, which solved the issue.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
In JIdea 2020.1.2 and above,
Go to Project Structure [ Ctrl+Alt+Shift+S
]
Select Modules sub section
Select each module
Under sources-section, check Language Level
Change the Language Level as required
NOTE:
If you get below error after this change,
Error:java: Compilation failed: internal java compiler error
You have to change the target bytecode version as well.
Go to Settings [ Ctrl+Alt+S
]
Select Java Compiler
Select module in the table
Change the byte-code version to map what you selected in the previous step for language-level