gpt4 book ai didi

src/test/java 中的 Mapstruct 映射器不是由 maven build 生成的

转载 作者:行者123 更新时间:2023-12-04 00:35:57 25 4
gpt4 key购买 nike

正如标题所说,我在src/test/java中有一个mapper接口(interface),它不是由mapstruct处理器生成的。

在同一个项目中,生成src/main/java中的所有映射器。这是预期的行为吗?

如何在测试源中生成映射器?

编辑(更多信息):

简化的 Maven 模块结构:

root_project
-> module_1

root_project的pom.xml

<build>
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.1.0.Final</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
</compilerArgs>
</configuration>
</plugin>
...

module_1 的 pom.xml 基本上是空的:

<dependencies>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<scope>compile</scope>
</dependency>

最佳答案

我遇到了同样的问题并通过更改 maven 编译器插件版本修复了它。请注意版本:Compiler 3.5.1Mapstruct 1.1.0.Final

            <!-- compiler plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>1.1.0.Final</version>
</dependency>
</dependencies>
<configuration>
<source>1.8</source>
<target>1.8</target>
<optimize>true</optimize>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.1.0.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

关于src/test/java 中的 Mapstruct 映射器不是由 maven build 生成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42713870/

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