java: log cannot be resolved
Asked Answered
G

8

5

i meet a problem I use

IntelliJ IDEA 2017.3.1 
Build #IU-173.3942.27, built on December 11, 2017
JRE: 1.8.0_111-b14 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
Windows 7 6.1

Error:(16, 10) java: log cannot be resolved

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;


@Slf4j
public class LogTest {

    @Test
    public void testSlf4j(){
         log.info("测试 lombok slf4j logback");
    }

}

i had config Settings -> Build, Execution, Deployment -> Compiler -> Annotation Enable annotation processing

Settings -> Other Settings -> Lombok

    <!-- SLF4J -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version>
    </dependency>
    <!-- Logback -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
        <version>1.7.21</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.20</version>
    </dependency>
Gastrolith answered 12/1, 2018 at 6:37 Comment(3)
Could you please attachscreenshot with your Annotation Processor settings? Have you tried to run "File | Invalidate Caches" and "Refresh" from maven tool window?Charry
where did to define the "log" variableDeina
For Intellij + Maven, try this https://mcmap.net/q/135462/-building-with-lombok-39-s-slf4j-and-intellij-cannot-find-symbol-logPredacious
G
4

I faced the same issue. A simple maven update helped me. You can try the following from command line:

mvn clean install -U

and then run your application

mvn spring-boot:run
Glazier answered 27/4, 2021 at 11:4 Comment(0)
A
2

Probably you have to install Lombok Plugin so that IDEA would know what does that annotation means.

Anomalous answered 12/1, 2018 at 20:31 Comment(0)
W
2

In addition to making sure you have the Lombok Plugin installed you also need annotation processing enabled.

After that I started to get this error and I needed to do a 'Build > Rebuild Project' to shake it off.

Winton answered 17/1, 2021 at 6:32 Comment(0)
N
2

I had the same problem, in my case, the compiler configuration was wrong because the Ajc compiler was selected, so I change it to Javac instead.

Config path:

File > Settings > Build, Execution, Deployment > Compiler > Java Compiler

Nurserymaid answered 27/7, 2021 at 15:31 Comment(0)
C
1

Do you have a lombok.config file that renames to log variable to something else using lombok.log.fieldName = xxx?

Cruciform answered 15/1, 2018 at 9:42 Comment(1)
And where should this configuration be set? It is not explained very well in the docsInfundibuliform
S
0

It may be related to @Slf4j and may be you are using any latest version of project lombok (1.18.x)+ try to install the earlier versions like 1.16.x which supports @Slf4j.

And then restart eclipse and rebuilt the project.

Scandic answered 19/8, 2019 at 6:18 Comment(0)
U
0
  1. Exit from the IDE.
  2. C:\Users{pcname}.m2\repository\org\projectlombok In this location delete all files.
  3. Download Lombok jar from https://projectlombok.org/download , and start IDE.
  4. Specify your IDE path like this.. Image to specify ide path
  5. Start your IDE.
Unarm answered 13/1, 2023 at 13:12 Comment(1)
When I looked at the image, it felt more like Eclipse. The question specifically states the person is using Intellij.Bilbao
C
-1

1.Go to https://projectlombok.org/ 2.Download JAR file. 3.Run JAR file. Usually double-clicking JAR file is enough. 4.In the Lombok installation screen, make sure that your Spring Tool Suite instance is listed. 5.Click Install/Update, then Quit Installer. 6.Open Spring Tool Suite, go to About Spring Tool Suite. The large area that contains the version number should have the Lombok version listed at the bottom. You might have to scroll, even though there is no scroll bar.

All the Best.

Convoluted answered 10/2, 2022 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.