Home >Java >javaTutorial >Why Does My Project Fail to Compile When Using MapStruct and Lombok Together?
MapStruct and Lombok Integration with Project Not Compiling
Issue:
When using MapStruct and Lombok together in a project, errors arise due to the unknown property "id" in the result type when getters and setters are removed with @Getter and @Setter annotations.
Resolution:
The issue stems from Maven using only the MapStruct processor but not the Lombok processor. To address this, two options are available:
Option 1: Add Lombok Dependency to Annotation Processor Paths
Modify the maven-compiler-plugin configuration in pom.xml to include the Lombok dependency in the annotationProcessorPaths:
<!-- Maven Compiler Configuration --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <!-- ... Existing Configuration Snippet --> <annotationProcessorPaths> <!-- Lombok Dependency --> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${org.projectlombok.version}</version> </path> <!-- MapStruct Dependency --> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${org.mapstruct.version}</version> </path> </annotationProcessorPaths> </configuration> </plugin>
Option 2: Add MapStruct-Processor Dependency
Alternatively, add the mapstruct-processor dependency to the dependencies in pom.xml and remove the annotationProcessorPaths:
<!-- Maven Dependencies --> <dependencies> <!-- ... Existing Dependencies Snippet --> <!-- MapStruct Processor Dependency --> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${org.mapstruct.version}</version> </dependency> </dependencies>
Additional Notes:
The above is the detailed content of Why Does My Project Fail to Compile When Using MapStruct and Lombok Together?. For more information, please follow other related articles on the PHP Chinese website!