Lombok Not Generating Getters in Spring Boot with MapStruct & Maven (Java 21)

I'm working on a Spring Boot project and facing an issue where Lombok is not generating getters for my entity class. Despite using @Data or @Getter, the getters are missing at compile time, leading to errors like "cannot find symbol getEmail()". My Setup (Dependencies & Plugins in pom.xml):
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional> <!-- Tried removing this -->
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-proc:full</arg> <!-- Tried adding this -->
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional> <!-- Tried removing this -->
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-proc:full</arg> <!-- Tried adding this -->
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
3 Replies
JavaBot
JavaBot7d ago
This post has been reserved for your question.
Hey @Patel! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Patel
PatelOP7d ago
Tried Solutions from GitHub Issues & Community: ✅ Added -proc:full to <compilerArgs> under maven-compiler-plugin ✅ Removed <optional>true</optional> from Lombok dependency ✅ Enabled annotation processing in IntelliJ/Eclipse settings ✅ Checked for conflicting imports of User class ✅ Rebuilt the project using mvn clean install & mvn clean compile However, Lombok-generated methods are still missing! 💡 Any ideas on what could be causing this issue in my Spring Boot project? 🚀 Hey everyone! I finally figured out why Lombok wasn't generating getters in my Spring Boot project. 🤦‍♂️ Turns out, I forgot to add Lombok as an annotation processor inside annotationProcessorPaths for MapStruct in maven-compiler-plugin. Adding this fixed it:
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.lombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.lombok.version}</version>
</path>
Hopefully, this saves someone else the headache! 😅🚀
JavaBot
JavaBot7d ago
Post Closed
This post has been closed by <@1046485112902127736>.

Did you find this page helpful?