mapstruct + lombok整合编译报错问题
编译代码报mapstruct相关错误,解决办法, 参考地址
- 方案1,把lombok放在mapstruct之前(不推荐)
- 方案2,引入如下依赖,可以无视lombo和mapstruct的顺序
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
<scope>provided</scope>
</dependency>
- mapstruct版本问题,用如下版本即可
<org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
build标签:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
如果依然报错,那么在idea的compiler设置中配置:
-Djps.track.ap.dependencies=false