idea较新版本识别不了lombok生成的方法
现象
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依赖的 javac方式的 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.
本文来自博客园,作者:mushishi,转载请注明原文链接:https://www.cnblogs.com/mushishi/p/14835575.html