Maven 打包报错 Couldn't retrieve @Mapper annotation

Maven Lombok MapStruct About 2,422 words

错误信息

Maven打包mvn clean package时会抛出以下错误

Couldn't retrieve @Mapper annotation

原因

pom.xml中父``pom或其他依赖中存在低版本的MapStruct。可通过Maven Dependency依赖分析查看MapStruct版本。

解决方法

exclude排除不同版本,使用相同版本的MapStruct

plugin pom

注意:Lombok版本大于1.18.16时,需要添加lombok-mapstruct-binding

lombok<1.18.16时:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>11</source>
        <target>11</target>
        <annotationProcessorPaths>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>1.4.2.Final</version>
            </path>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.12</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>

lombok>1.18.16`时:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>11</source>
        <target>11</target>
        <annotationProcessorPaths>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>1.4.2.Final</version>
            </path>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.12</version>
            </path>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-mapstruct-binding</artifactId>
                <version>0.2.0</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>

参考

https://mapstruct.org/faq/#Why-do-I-get-this-error-Could-not-retrieve-Mapper-annotation-during-compilation

Views: 5,951 · Posted: 2022-07-20

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh