如何解决是否可以将 mapstruct 与 jpastreamer 一起使用?
我正在编写一个使用 mapstruct 的 spring-boot 项目。 mapstruct 生成的代码位于 target/generated-sources/annotations
中。
我也想使用 jpastreamer 库。我使用 build-helper-maven-plugin
生成元模型。
我面临的问题是这个库也会在同一个目录下生成 metamodel
,所以只有 mapstruct 生成的代码可用。
这是我的代码:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
<source>16</source>
<target>16</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
解决方法
我不知道 jpastream 是哪个库。但是,如果它是注释处理器,那么您应该将其作为 maven-compiler-plugin
annotationProcessorPaths
的一部分包含在内。这样所有的注解处理器都会被同时调用,代码会被适当地生成。
您只能在 target/generated-sources/annotations
文件夹中看到 MapStruct 生成的代码,这是因为 maven-compiler-plugin
在运行注释处理器之前删除了该文件夹中的所有内容。
如果该 jpastream 库不是注释处理器而是其他东西,那么您应该在另一个位置生成它的类,而不是 target/generated-sources/annotations
,而是 target/generated-sources/jpastream
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。