【踩坑idea 2021.2.3】【Gradle】 Building with Lombok‘s @Slf4j and Intellij: Cannot find symbol log

对于idea 2020.3以上版本都带有lombok插件,用maven正常运行的项目,由于改用gradle7.3,导致报错Cannot find symbol log,排查lombok有问题,将注意事项记录一下,希望对大家有用。

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestClass
{
    public TestClass()
    {
        log.info("Hello!");
    }
}

第一步:使能 Annotation Processor,windows路径File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processor,mac路径Preferences-> Build, Execution, Deployment -> Compiler -> Annotation Processor

【踩坑idea 2021.2.3】【Gradle】 Building with Lombok‘s @Slf4j and Intellij: Cannot find symbol log_第1张图片

第二步:在build.gradle中,增加 dependency

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

 如果在tests也有调用,需要添加下面注释

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

可以参考一下:

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

你可能感兴趣的:(Springboot,intellij-idea,gradle,java,Lombok)