gradle编译Lombok报错No processor claimed any of these annotations

来源:12-4 Spring容器是执行refresh方法的入口

qq_金风未动蝉先觉_0

2020-10-27

在spring mvc demo中的build.gradle配置文件中:

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

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

但是在启动tomcat时报错:

警告: 没有处理程序要使用以下任何注释: org.springframework.context.annotation.Configuration,org.springframework.web.bind.annotation.RequestParam,org.springframework.stereotype.Service,org.springframework.web.bind.annotation.RequestMapping,org.springframework.beans.factory.annotation.Autowired,org.springframework.web.servlet.config.annotation.EnableWebMvc,org.springframework.context.annotation.Bean,org.springframework.stereotype.Controller,javax.annotation.processing.SupportedAnnotationTypes,org.springframework.context.annotation.ComponentScan
错误: 发现警告, 但指定了 -Werror

最终编译失败,网上的解决方案是用-Xlint:-processing沉默警告,但是并没有起作用

写回答

1回答

翔仔

2020-10-28

同学好,请问源码是不是用的github的,需要用github上面的官方源码才可以,此外,光看这些信息我这边没法精确定位问题呢,查了一下,最贴切的如下

This doesn't really have anything to do with Lombok specifically. It will happen with any annotation processor on the classpath. The warning is indicating that annotation processing was performed during compilation and that none of the annotation processors handled an annotation. Note that there's nothing special about @SpringBootApplication and that it'll warn about any unhandled annotation
IMO, it's not a very helpful warning as it assumes that every annotation in a project's code will be handled by an annotation processor. Given that anyone can write an annotation and that there are many other uses for annotations other than processing during compilation, that assumption seems flawed to me.
I think you have two choices:
Ignore the warning
Write your own annotation processor that does nothing other than using @SupportedAnnotationTypes to declare all of the annotations that you want to use in your code that you don't want to be warned about.

看起来说的是有些annotation没被处理,感觉是缺少某些关联的jar导致的,复制下课程的build.gradle试试

0
0

剑指Java自研框架,决胜Spring源码

快速入门Spring核心源码+从零开发自研框架

1498 学习 · 495 问题

查看课程