Lombok annotations do not compile under Intellij IDEA
To conquer Lombok obstacles in IntelliJ IDEA, verify that the Lombok plugin is engaged. Head on to Preferences/Settings -> Plugins, punch in 'Lombok', and get it up and running. Subsequently, authorize annotation processing: Preferences/Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors, and select 'Enable annotation processing'. Confirm the presence of lombok
in your build concoction:
Maven:
Gradle:
Substitute [latest]
with the top-drawer Lombok version. All aboard the fast track to Lombok heaven!
Peeling the onion: Extended troubleshooting
Compatibility check: Plugin and lombok
Let's ensure that your shiny IntelliJ IDEA release and Lombok plugin version are bearing up well. Upgrades may call for some fine-tuning of Lombok plugin. Worry not, the official templates or community banter on IntelliJ Marketplace reviews are there for us.
JDK Version is no joke
Another round of checks: your JDK version and its peace pact with Lombok. An update could open or close gates for specific JDK versions. Hip-check your JDK against Lombok's requirements to avoid tripping up.
Gradle and IntelliJ: BFFs
For the Gradle disciples, passing the torch of build/run actions to Gradle (IntelliJ settings) can smoothen many a crease with Lombok. Go to Preferences/Settings -> Build, Execution, Deployment -> Build Tools -> Gradle and choose to delegate IDE build/run actions to Gradle.
Maven magic: Project refresh
Never fear, Maven users, we've got you covered too! If those plugins are acting pricey, refresh your project's configuration with the magic spells of mvn idea:clean
followed by mvn idea:idea
.
Eclipse Compiler: The unsung hero
Complex Lombok predicaments may pay due reverence to the Eclipse compiler. IntelliJ IDEA has its arms wide open for the switch under Preferences/Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler.
The shadow lands: Deeper diagnostics
Inspector Lombok: .class files
If Lombok plays coy despite plugin smoothly running, try peeking into .class
files generated by IntelliJ. Play Sherlock to the Lombok-generated methods.
Lombok: The javaagent
For the brave and the bold, try bringing Lombok on as a sidekick VM option during the build show. The magic trick here is setting -javaagent:path/to/lombok.jar
.
Editor acknowledgment: The game of optics
The tricky editor may brand Lombok getters and setters as outlaws even when Lombok is the law. If this happens, the plugin may be at odds with the rules.
Gradle: The test knight
At times, the knight in the test execution, ensure Lombok-annotated classes run through Gradle in any joust with the IDE.
The secret keys: Alternative setup strategies
Jigsaw: Your modular mate
For a crack at the future,
do test waters with Jigsaw modules and Lombok. The module-info.java
should pay homage to Lombok with a marked requires lombok;
Lombok goes global
Set up lombok.jar in the Global Libraries and bring it on board as a locked-in module. Such a global approach doesn't let local projects trip over missing lombok jars.
Fresh start: IntelliJ configuration files
In case of corrupted or complex IntelliJ configurations, it never hurts to burn it down and start afresh. Regenerating IntelliJ project files might be the silver lining you need.
Was this article helpful?