maven - 映射结构 : generated sources in intelliJ using annotationProcessorPaths

标签 maven intellij-idea annotation-processing mapstruct

我使用 Eclipse IDE 开发了一个使用 Mapstruct 的应用程序,现在我正转向 IntelliJ 继续开发。

在 Eclipse 上一切正常,但由于使用了 annotationProcessorPaths,我在 IntelliJ 上出现了意外行为。

我的配置如下:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
    <annotationProcessorPaths>
        <path>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <version>${mapstruct.version}</version>
        </path>
    </annotationProcessorPaths>
    <source>${java.version}</source>
    <target>${java.version}</target>
    <compilerArgs>
        <compilerArg>
            -Amapstruct.defaultComponentModel=${mapstruct.defaultComponentModel}
        </compilerArg>
        <compilerArg>
            -Aorg.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
        </compilerArg>
    </compilerArgs>
</configuration>

在 IntelliJ 上,当我启动 Maven 全新安装时,我得到了生成的源代码:

@Component

public class FieldMapperImpl implements FieldMapper {

    @Autowired

    private FieldMapperResolver fieldMapperResolver;

...
}

但是当我运行/调试我的 Spring Boot 应用程序时,我得到的生成源是:

public class FieldMapperImpl implements FieldMapper {

    private final FieldMapperResolver fieldMapperResolver = new FieldMapperResolver();
    ...
    }

我该如何解决这个问题?

最佳答案

我假设您正在直接通过 IntelliJ 运行/调试 Spring Boot 应用程序。发生这种情况的原因是因为 IntelliJ 不会从 maven-compiler-plugin 中获取配置。参见 IDEA-143742IDEA-150621 .

您还必须单独配置 IntelliJ 注释处理器选项。你可以在 Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors 中找到它

奇怪的是 IntelliJ 甚至如何调用处理器,你的 pom 中是否也有 mapstruct-processor 作为依赖项?

编辑: IntelliJ 不获取 maven-compiler-plugin 编译器参数。默认组件模型是通过注释处理器选项设置的。为了使 IntelliJ 正常工作,应该在 IntelliJ 配置中设置相同的属性或使用 @Mapper(componentModel = "spring")。更多信息在 documentation

关于maven - 映射结构 : generated sources in intelliJ using annotationProcessorPaths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43585890/

相关文章:

java - 是否有任何强大的 Clojure 持续集成选项?

java - 我应该如何从另一个spring项目中调用打包的spring项目?

java - Intellij 不使用库构建 JavaFX

java - 如何通过注解处理工具获取extends接口(interface)?

java - TypeElement 与 TypeMirror 作为 Java 注释处理器的数据模型

maven - 在 tomcat-server 中部署时与应用程序的依赖关系问题

java - 野蝇 10 号和 jackson 2 号

java - "PKIX path building failed: unable to find valid certification path to requested target"仅在发布版本中

java - IntelliJ IDEA 表示本地主机端口已经繁忙

java - 注解处理第三方库