MapStruct and Lombok Integration: Resolving the "Unknown Property" Error
When using MapStruct with Lombok annotations, you may encounter an error stating "Unknown property in result type." This error arises because Maven only employs the MapStruct processor and not the Lombok processor.
Option 1: Modify the Maven Compiler Plugin
Update the maven-compiler-plugin configuration to include both the Lombok and MapStruct annotation processor paths:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <annotationProcessorPaths> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${org.projectlombok.version}</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> <version>0.2.0</version> </path> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${org.mapstruct.version}</version> </path> </annotationProcessorPaths> </configuration> </plugin>
Option 2: Declare MapStruct as a Dependency
Alternatively, add the mapstruct-processor dependency to the main dependencies section and remove the annotationProcessorPaths:
<dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${org.mapstruct.version}</version> </dependency>
Additional Considerations for IntelliJ
To prevent IntelliJ errors, add the mapstruct-processor as a provided dependency:
<dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${org.mapstruct.version}</version> <scope>provided</scope> </dependency>
Note for Lombok Versions
For Lombok versions 1.18.16 and above, you will require the lombok-mapstruct-binding dependency to ensure proper integration with MapStruct.
The above is the detailed content of How to Fix \'Unknown Property\' Errors When Using MapStruct with Lombok?. For more information, please follow other related articles on the PHP Chinese website!