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

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?


Solution 1:

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

Solution 2:

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?

Solution 3:

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

The following additional checkbox helps: enter image description here

Solution 4:

2019:

Get a plugin and you are sorted...

File > Settings > Plugins

enter image description here

Solution 5:

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.