I have a maven project that builds with no problems from the command line. However, when I build it with IntelliJ, I get the error:
java: FileName.java:89: cannot find symbol
symbol : variable log
There is no log defined or imported in the java file, but there is a
@Slf4j
final public class FileName {
statement before the class body which should define the log class.
In the project structure window, classes for:
Maven: org.slf4j:jcl-over-slf4j:1.6.1
Maven: org.slf4j:slf4j-api:1.6.6
Maven: org.slf4j:slf4j-log4j12:1.6.6
Maven: org.slf4j:slf4j-simple:1.6.6
are listed under libraries and are indicated as having been downloaded and available.
Any idea why this would build with maven through the command line, but not through IntelliJ and how to resolve the issue?
This question is related to
intellij-idea
slf4j
lombok
I was seeing this issue with an older version of Lombok when compiling under JDK8. Setting the project back to JDK7 made the issue go away.
Itsn't a IntelliJ problem. If you try under console, run mvn install, also breaks. All annotations from lombok.extern needed add dependencies. This package groups the next annotations:
For example, for Slf4j it's necessary add this dependency to your pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
This worked for me :
File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processor
Tick on 'enable annotation processing'.
Apply
Close
Removing the @Slf4J annotation from the class and then re-adding it worked for me.
I have the same issue; I use gradle and IDEA;
It turns out that, it's caused by the wrong version of gradle.
In gradle\wrapper\gradle-wrapper.properties, it is:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
However, I specified the version in IDEA to be
D:\Library\gradle-5.2.1
After lower the gradle version to be 4.10.x, the issue is gone.
A simple thing but I figured it out is: I missed adding @Log
to the class.
@Log
public class YourClassName {
}
It may help someone.
After enabling annotation processors and installing the lombok plugin, it still didn't work. We worked around it by checking the Idea option "Delegate IDE build to gradle"
I've just installed the latest idea verion 2108.1 and found this issue, after installed lombok plugin and restart the Idea resolve it.
Presumably, that's the Lombok @Slf4j annotation you're using. You'll need to install the Lombok plugin in IntelliJ if you want IntelliJ to recognize Lombok annotations. Otherwise, what do you expect if you try to use a field that doesn't exist?
I had Lombok plugin, annotations enabled, it was compiling from command line - everything and it still did not see my project as maven (all maven dependencies were red in source files). Then I clicked SHIFT twice and searched for 'maven' and among results there was 'Reload all Maven Projects'. After running it Maven tab appeared and I was able to compile, and all red underlining in source code disappeared.
So if the issue persists even after enabling the annotation processing and installing the Lombok plugin.
There's an issue with IDEA 2020.3 and Lombok, you could fix this by following this fix.
basically, add -Djps.track.ap.dependencies=false
to the VM options, you can find it in: Preferences -> Compiler. Named 'Shared build process VM Options'
What sorted out things for me was to tick the checkbox "Use plugin registry" in Maven settings.
The path is: File -> Preferences -> Build, Execution, Deployment -> Build Tools -> Maven
I might be ungraving a dead topic but a simple solution is to check in your dependencies (Maven's pom for exemple) if you are including logback-core and logback-classic.
Slf4j is just the interface, you need the concrete implementation behind it to work.
I've been tricked twice with IDEA messing it up, now I'm good to go :D
I tried almost all of the mentioned answers but nothing worked for me. My gradle build was failing every time. Just found this solution:
Add annotationProcessor 'org.projectlombok:lombok'
in your build.gradle.
This worked for me.
There is the following step to be followed here:
Step 1. Enabled annotation processing for your project under File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processor
Step 2. Install lombok plugin in IntelliJ IDE after that restart IDE. Screenshot
Step 3. Add the dependency in build.gradle file.
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
hope this answer is helpful for you.
This is another related post Lombok not working with IntelliJ 2020.3 Community Edition which may resolve the question when user use lombook
and IntelliJ 2020.3 CommunityEdition
.
1 My gradle lombok dependecies:
implementation 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
2 After enabling "Annotations..." in IDEA (Settings), taking into account that you have installed Lombok plugin, that resolved my the same issue
In addition to having Lombok plugin installed, also make sure that the "Enable annotation processing
" checkbox is ticked under:
Preferences > Compiler > Annotation Processors
Note: starting with IntelliJ 2017, the "Enable Annotation Processing
" checkbox has moved to:
Settings > Build, Execution, Deployment > Compiler > Annotation Processors
Worked for me!!! It was failing on CircleCI & on Jenkins as well.
If you're a Gradle User try add the following into your dependencies:
dependencies {
//Other Dependencies >>
//LOMBOK Dependencies
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
}
If you are using maven, try adding Lombok path to maven-compiler-plugin
list of annotation processor as shown below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Change the version as per your version of Lombok. Other than that ensure you have done the following
File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processor
. For me both, Obtain processors from project classpath
and Processor path
is working. So not sure what will work for you, but try whichever works.And rather than shooting in the dark for hours. Reading a little bit how annotation processors work and are used by compiler may help. so have quick read below.
http://hannesdorfmann.com/annotation-processing/annotationprocessing101
This won't have been OP's problem, but for anyone else who tries everything with no success:
I had similar symptoms. Whenever I built after a mvn clean
, it wouldn't find log
, or getXYZ()
, or builder()
, or anything.
[ERROR] symbol: variable log
[ERROR] location: class com.example.MyClass
[ERROR] /Path/To/Some/Java/src/main/com/example/MyClass.java:[30,38] cannot find symbol
[ERROR] symbol: method builder()
[ERROR] location: class com.example.MyClass
After reading every answer I could find about QueryDSL/JPA/Hibernate/Lombok/IntelliJ/Maven issues to no avail, I worked out that the culprit was a single static import of a @Getter
method that was annotated on a static field.
Spring 1.15.14.RELEASE, Intellij 2019.1.1
@SpringBootApplication
public class BarApplication implements ApplicationContextAware {
@Getter
private static ApplicationContext applicationContext;
// ... start Spring application, and grab hold of ApplicationContext as it comes past
}
import ...
import static BarApplication.getApplicationContext;
@Slf4j
public class IMakeItAllFail {
public IMakeItAllFail() {
log.info("{}", getApplicationContext());
}
}
@Slf4j
public class Foo {
Foo() {
log.info("I fail to compile but I have nothing to do with the other classes!");
}
}
I had the same kind of error, right after a warning like the following:
java: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: com.sun.proxy.$Proxy27
Lombok supports: OpenJDK javac, ECJ
In my case, it was an unfortunate combination of lombok < 1.18.16 and IDEA 2020.3.
Delete .idea folder and .iml files in each module and rebuild the solution.
Try to create lombok.config
file under project base directory and provide lombok.log.fieldName
value.
Example: lombok.log.fieldName = LOG
In IDEA 13 this seems to no longer be an issue, you just have to have the Lombok plugin installed.
Source: Stackoverflow.com