MapStruct and Lombok not working together
Problem
When attempting to learn mapstruct as a new tool, I discovered that it does not seamlessly integrate with lombok annotations such as @AllArgsConstructor, as it suggests that the constructor does not exist. However, once I manually create the constructor, everything operates as intended. Clearly, the lombok annotation is not functioning as expected.
Cause
The reason why it does not work is because Maven only uses the MapStruct processor and not the Lombok one. The annotationProcessorPaths tells maven which processors it should use.
Simple solution:
- add maven dependency:
Don’t forget the
lombok-mapstruct-bindingdependency
1 | <dependency> |
- add necessary annotation processor paths to maven plugin:
add lombok related paths
1 | <plugin> |
And, voila! Everything’s working fine now.
ref
https://stackoverflow.com/questions/47676369/mapstruct-and-lombok-not-working-together
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
