現象
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
在這增加參數: -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.