Mapstruct + Lombok together not compiling: unknown property in result type
Let's get Lombok and MapStruct in line to avoid those pesky compilation errors. Your mission, if you choose to accept it, is to give your maven-compiler-plugin The Order:
Don't forget to replace LATEST_LOMBOK_VERSION
and LATEST_MAPSTRUCT_VERSION
with your current versions. This strategy ensures Lombok's eager code generation finishes before MapStruct—и voilà, no more unknown property
errors.
Harmonizing Lombok and MapStruct: Configurations and setups
Maven and Gradle: The dynamic duo
With Maven, you should add the lombok-mapstruct-binding
; it's the peace treaty for Lombok version 1.18.16 and above. Who knew it was that easy to solve interoperability issues?
For those of you who are on team Gradle, here's your playbook:
Again, replace latest
with the latest versions. We don't want you living in the past.
IntelliJ: The master of ceremony
Even IntelliJ has a role to play. Enable its annotation processing by:
- Exploring Settings / Preferences.
- Treading the path to Build, Execution, Deployment > Compiler > Annotation Processors.
- Embracing the Enable annotation processing.
You might have to make sure the source
and target
are set to Java 8 or your respective version in IntelliJ's settings. An educated IDE equals a smooth compilation process.
Pragmatic guide: Unlocking a seamless integration
Conflict resolution
You may get your hands dirty when smoothing out:
- Delombok. Don't create pandemonium by stripping out Lombok annotations before MapStruct can see them.
- Rely on
@Getter
and@Setter
when necessary instead of@Data
. It minimums magic but puts you on the driver's seat. - Keep
@MapperConfig
at bay with MapStruct when it cross paths with Lombok.
Under the hood
To play Sherlock, inspect the generated implementations post a clean build:
- Check if all Lombok generated methods are in the brigade.
- Ensure MapStruct's masterpieces have the desired mappings.
Maven setting
Set your project's source and encoding to UTF-8 to ward off any "lost in translation" issues.
Keep libraries fancy and fresh
Consistent updates of both Lombok and MapStruct to compatible versions keep things running like a Swiss watch.
Was this article helpful?