Mapstruct
Chu*_*k94 5
解决了!
问题是由于编译的顺序。默认情况下,java 编译器在 kotlin 编译器之前执行。这就是为什么 mapstruct 生成的代码无法找到 kotlin 类的原因。因此需要先编译 koltin 类,然后再编译 java 类。
“这个想法是禁用默认编译执行并引入我们自己的来控制目标执行的顺序,这样我们就可以在 java 编译器之前运行 kotlin 编译器。”
discuss.kotlinlang./t/maven-piler-plugin-question/5260/4
所以解决方案来了引入 maven 插件:
kotlinlang./docs/maven.html#pile-kotlin-and-java-sources
所以我将它添加到我的 pom 文件中:
<plugin> <groupId>.apache.maven.plugins</groupId> <artifactId>maven-piler-plugin</artifactId> <executions> <!-- Replacing default-pile as it is treated specially by maven --> <execution> <id>default-pile</id> <phase>none</phase> </execution> <!-- Replacing default-testCompile as it is treated specially by maven --> <execution> <id>default-testCompile</id> <phase>none</phase> </execution> <execution> <id>java-pile</id> <phase>pile</phase> <goals> <goal>pile</goal> </goals> </execution> <execution> <id>java-test-pile</id> <phase>test-pile</phase> <goals> <goal>testCompile</goal> </goals> </execution> </executions> </plugin>Mapstruct