mapstruct + lombok整合编译报错问题

编译代码报mapstruct相关错误,解决办法, 参考地址

  1. 方案1,把lombok放在mapstruct之前(不推荐)
  2. 方案2,引入如下依赖,可以无视lombo和mapstruct的顺序
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok-mapstruct-binding</artifactId>
    <version>0.2.0</version>
    <scope>provided</scope>
</dependency>
  1. 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

posted @ 2022-11-28 17:16  神一样的存在  阅读(669)  评论(0编辑  收藏  举报