Home >Java >javaTutorial >Why Does MapStruct Fail to Recognize Lombok\'s @Getter and @Setter Annotations, and How Can I Fix It?
Integrating MapStruct and Lombok can lead to the error "Unknown property ... in result type ..." when using @Getter and @Setter annotations on entity and DTO classes together. This occurs despite the versions of both libraries being compatible.
The issue arises because Maven uses the MapStruct processor exclusively, ignoring the Lombok one. To resolve this:
In the Maven compiler plugin configuration, add the Lombok dependency to the annotationProcessorPaths list:
<annotationProcessorPaths> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${org.projectlombok.version}</version> </path> ... </annotationProcessorPaths>
Additionally, for Lombok 1.18.16 and above, add the following path:
<path> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> <version>0.2.0</version> </path>
Alternatively, add the MapStruct processor as a dependency and remove the annotationProcessorPaths:
<dependencies> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${org.mapstruct.version}</version> </dependency> </dependencies>
NOTE: Option 1 is recommended to ensure that no internal MapStruct classes are referenced in the code.
To enable annotation processing in IntelliJ, add the MapStruct processor as a provided dependency due to [IntelliJ issue IDEA-150621](https://youtrack.jetbrains.com/issue/IDEA-150621).
The above is the detailed content of Why Does MapStruct Fail to Recognize Lombok\'s @Getter and @Setter Annotations, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!