gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:29:52 24 4
gpt4 key购买 nike

我有一个 Spring Boot 项目,它有 lombok 和 mapstruct 并使用 Maven 作为构建工具。我需要在编译时处理注释,并将生成的源代码与最终的 jar 一起打包。构建成功。然而,最终的 jar 缺少 mapstruct 实现类。当我尝试启动 Spring Boot 应用程序时出现错误:


APPLICATION FAILED TO START


Description:

Field salesforceObjectMapper in com.some_org.service.salesforce.object.processor.SalesforceObjectProcessor required a bean of type 'com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper' that could not be found.

Action:

Consider defining a bean of type 'com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper' in your configuration.

这是我的 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>

最佳答案

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

<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>

关于java - 如何通过 maven-compiler-plugin 使用多个注释处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61143001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com