如何通过maven-compiler-plugin使用多个注释处理器

问题描述 投票:0回答:1

我有一个包含lombok和mapstruct并使用maven作为构建工具的spring boot项目。我需要在编译时处理注释,并将生成的结果源与最终jar打包在一起。构建成功。但是,最终的jar缺少mapstruct实现类。我尝试启动Spring Boot应用程序时的错误是:


申请无法开始


说明:

字段salesforceObjectMapper在com.some_org.service.salesforce.object.processor.SalesforceObjectProcessor需要一个类型的bean'com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper'找不到。

动作:

考虑定义类型的bean'com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper'在您的配置中。

这是我的maven-compiler-plugin设置:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <annotationProcessorPaths>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.12</version>
            </path>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>1.2.0.Final</version>
            </path>
        </annotationProcessorPaths>
        <compilerArgs>
            <compilerArg>-Amapstruct.suppressGeneratorTimestamp=true</compilerArg>
            <compilerArg>-Amapstruct.suppressGeneratorVersionInfoComment=true</compilerArg>
        </compilerArgs>
    </configuration>
</plugin>
java spring-boot maven lombok mapstruct
1个回答
0
投票

最终通过在编译阶段使用执行来覆盖默认的编译目标来解决此问题,如下所示:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <executions>
        <execution>
            <id>Compile With Annotation Processing</id>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.18.12</version>
                    </path>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>1.2.0.Final</version>
                    </path>
                </annotationProcessorPaths>
                <compilerArgs>
                    <compilerArg>-Amapstruct.suppressGeneratorTimestamp=true</compilerArg>
                    <compilerArg>-Amapstruct.suppressGeneratorVersionInfoComment=true</compilerArg>
                </compilerArgs>
            </configuration>
        </execution>
    </executions>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.