IDEA中的Lombok失效问题

现象

IDEA中的springboot工程,引入了依赖Lombok,配置

<build>
    <plugins>
       <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
             <annotationProcessorPaths>
                <path>
                   <groupId>org.projectlombok</groupId>
                   <artifactId>lombok</artifactId>
                </path>
             </annotationProcessorPaths>
          </configuration>
       </plugin>
       <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <configuration>
             <excludes>
                <exclude>
                   <groupId>org.projectlombok</groupId>
                   <artifactId>lombok</artifactId>
                </exclude>
             </excludes>
             <profiles>
                <profile>dev</profile>
             </profiles>
          </configuration>
       </plugin>
    </plugins>
</build>

maven命令(mvn xxx)都正常,@Slf4j注解的类会自动生成 log变量,变量无红线

但是IDEA的build命令,报错找不到log,之所以发现这个是我右击了@Test注解的测试方法

java: 找不到符号
  符号:   变量 log
  位置: 类 com.mz502.springdemo.service.MyDemoService

解决方案

第一步

  • File → Settings → Build, Execution, Deployment → Compiler → Annotation Processors
  • 勾选 “Enable annotation processing”
  • 选择 “Obtain processors from project classpath”

第二步(有可能不需要)

  • File → Settings → Build, Execution, Deployment → Build Tools → Maven → Runner
  • 勾选 “Delegate IDE build/run actions to Maven”

原理还没特别明确,我觉得是IDEA自己编译与Maven编译存在差异,我更倾向于都交给Maven

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值