Search code examples
javaintellij-idealombokannotation-processingintellij-lombok-plugin

Why IntelliJ needs Lombok plugin?


As far as I understand, Lombok uses Java's Annotation Processors to generate additional methods.

With Maven 3.5 it works perfectly without adding any additional configuration, just add dependecy to Lombok and put some annotations like @Getter, @Setter.

However, if I open this project in IntelliJ IDEA 2018.2, all usages of generated getters/setters are highlighted as errors. I have Annotation Processing turned on, I tried to built project in IntelliJ or build in Maven and then use in IntelliJ, but it still requires Lombok Plugin to avoid false errors.

Is it some kind of bug? Error in workflow? Or maybe Lombok is using not only Annotation Processors, but some other stuff I didn't know and that's why IntelliJ + javac cannot figure out how to deal with it? It would be strange as javac itself compiles those files without errors

I know there are many questions "I have errors while using Lombok" and answers like "use the plugin". I'm not asking if I should use plugin, but why I should use it, why IntelliJ cannot handle it without plugin while javac does


Solution

  • IntelliJ's code analysis engine does not use javac or run annotation processors. Instead, IntelliJ uses its own Java parser and reference resolution logic, and builds its own code model. The Lombok plugin extends the code model to provide information about declarations generated by the Lombok annotation processor.