Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building with Lombok's @Slf4j and Intellij: Cannot find symbol log

People also ask

What does @Slf4j annotation do?

Annotation Type Slf4jCauses lombok to generate a logger field. Complete documentation is found at the project lombok features page for lombok log annotations. This annotation is valid for classes and enumerations.

What does error Cannot find symbol mean in Java?

The cannot find symbol error, also found under the names of symbol not found and cannot resolve symbol , is a Java compile-time error which emerges whenever there is an identifier in the source code which the compiler is unable to work out what it refers to.


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

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?


In Intellij version 2016, 2017, enable Preferences -> Compiler -> Annotation Processors does not work for me!

The following additional checkbox helps: enter image description here


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

Screenshot enter image description here

Step 2. Install lombok plugin in IntelliJ IDE after that restart IDE. Screenshot

enter image description here

Step 3. Add the dependency in build.gradle file.

 compileOnly 'org.projectlombok:lombok:1.18.12'
 annotationProcessor 'org.projectlombok:lombok:1.18.12'

In case you are using lombok in tests you need to add:

testCompileOnly 'org.projectlombok:lombok:1.18.12'  
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'

or https://developervisits.wordpress.com/2020/09/16/building-with-lomboks-slf4j-and-intellij-cannot-find-symbol-log/

hope this answer is helpful for you.


2019:

Get a plugin and you are sorted...

File > Settings > Plugins

enter image description here


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'
}