Pét*_*res 5 java lombok mapstruct quarkus
我正在遵循MapStruct 博客上的指南,但在同时使用这 3 种技术时遇到问题。我一直在尝试来自 MapStruct 文档、错误报告、此处帖子的几种方法,但在每种情况下,我最终都会在构建过程中收到以下异常。
有人在 Quarkus 下成功使用 MapStruct 和 Lombok 吗?任何帮助表示赞赏。
compile奇怪的是, a 后的第一个mvn clean总是成功,而第二个compile或运行应用程序会抛出此错误:
Error:(9,8) java: Internal error in the mapping processor: java.lang.RuntimeException:
javax.annotation.processing.FilerException: Attempt to recreate a file for type com.example.service.RawContentDtoMapperImpl
at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.createSourceFile(MapperRenderingProcessor.java:59)
at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.writeToSourceFile(MapperRenderingProcessor.java:39)
...
Run Code Online (Sandbox Code Playgroud)
映射器配置:
Error:(9,8) java: Internal error in the mapping processor: java.lang.RuntimeException:
javax.annotation.processing.FilerException: Attempt to recreate a file for type com.example.service.RawContentDtoMapperImpl
at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.createSourceFile(MapperRenderingProcessor.java:59)
at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.writeToSourceFile(MapperRenderingProcessor.java:39)
...
Run Code Online (Sandbox Code Playgroud)
映射器:
@MapperConfig(componentModel = "cdi")
public interface QuarkusMappingConfig {
}
Run Code Online (Sandbox Code Playgroud)
对于 pom.xml,我从我找到的所有 MapStruct+Quarkus 和 MapStruct+Lombok 安排指南中尝试了几种不同的方法。包括两个主要方法的相关部分:
共享属性
@Mapper(config = QuarkusMappingConfig.class, unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface RawContentDtoMapper {
RawContentDTO toResource(RawContent rawContent);
}
Run Code Online (Sandbox Code Playgroud)
1.使用插件annotationProcessorPaths
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
...
<org.mapstruct.version>1.4.0.Beta3</org.mapstruct.version>
<org.projectlombok.version>1.18.12</org.projectlombok.version>
</properties>
Run Code Online (Sandbox Code Playgroud)
2.使用mapstruct-processor依赖方法(使用和不使用方法#1中的maven-compiler-plugin,以及使用和不使用annotationProcessorPaths)
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</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>${org.projectlombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Run Code Online (Sandbox Code Playgroud)
在我们的例子中,它与 Quarkus 无关,而是与
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-generated-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${generated-sources-path}/wsdl</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
问题是我们的添加源源文件夹将生成的源和映射结构实现添加到源路径。然后映射结构处理器将尝试再次注册映射结构源,这将导致冲突。
解决方案:我必须更具体地说明add-sources文件夹路径并排除 mapstruct 放置生成的 Java 类的文件夹。
小智 1
谢谢@jste89。我只是反转注释处理器以使其正常工作
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.80</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7104 次 |
| 最近记录: |