现象
idea版本:
IntelliJ IDEA 2021.1.1 (Ultimate Edition)
Build #IU-211.7142.45, built on April 30, 2021
lombok版本
1.18.16
编译的时候报错:
java: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: com.sun.proxy.$Proxy32
Lombok supports: OpenJDK javac, ECJ
新版本idea所使用的的java compilier编译器,lombok用不来, 得是 javac
所以 @Getter @Setter 等lombok注解就没法在pre-compile的时候没法生成对应的方法了
问题排查
lombok的相关issue:https://github.com/projectlombok/lombok/issues/2592
IntelliJ is now wrapping the
ProcessingEnvironment
in aProxy
. This lead to a problem for us at MapStruct (mapstruct/mapstruct#2215). While trying to fix that and testing with our examples I realized that our examples with Lombok are not compiling anymore.
大致意思是,IntelliJ新版本在 ProcessingEnvironement 预编译的时候是以代理的方式来执行的,不再是直接 javac方式,所有 lombok依赖的 annotation processors
解决办法
IntelliJ的开发人员在这里有回复 https://youtrack.jetbrains.com/issue/IDEA-252069
Intellij使用包装类来编译是为了收集分析版本变更的影响以更好的编译文件, lombok的这个判断逻辑有点太死板了 他们得改
在这增加参数: -Djps.track.ap.dependencies=false
就能正常处理 lombok注解了,
同时提示
java: JPS incremental annotation processing is disabled. Compilation results on partial recompilation may be inaccurate.
Use build process "jps.track.ap.dependencies" VM flag to enable/disable incremental annotation processing environment.