How to Fix IntelliJ Annotation Processing — Lombok and MapStruct Issues
In this tutorial, you'll learn about How to Fix IntelliJ Annotation Processing. We cover key concepts, practical examples, and best practices.
The Problem
Annotation processors like Lombok and MapStruct are not working:
@Data // Lombok annotation — not generating getters/setters
public class User {
private String name;
}
Calling user.getName() shows "Cannot resolve symbol".
Quick Fix
Step 1: Enable annotation processing
File > Settings > Build, Execution, Deployment > Compiler > Annotation Processors
Check Enable annotation processing.
Step 2: Configure annotation processor
For Maven, the processor is auto-detected from the POM. For IntelliJ project:
Add the processor class:
Annotation Processors > Processor path: [project directory]/lib
Or use the classpath:
Annotation Processors > Obtain processors from project classpath
Step 3: Install the Lombok plugin for IntelliJ
File > Settings > Plugins > Marketplace > Search "Lombok" > Install
Then restart IntelliJ.
Step 4: Enable Lombok annotation processing
File > Settings > Build, Execution, Deployment > Compiler > Annotation Processors
Enable annotation processing and add:
Processors: lombok.launch.AnnotationProcessorHider$AnnotationProcessor
Step 5: Add Maven/Gradle dependencies
For Maven (pom.xml):
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
For MapStruct:
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<scope>provided</scope>
</dependency>
Prevention
- Enable annotation processing before adding Lombok or MapStruct.
- Install the Lombok plugin from the JetBrains Marketplace.
- Keep annotation processor versions aligned with your build tool.
Common Mistakes with annotation processing
- Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists
These mistakes appear frequently in real-world INTELLIJ code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro