【问题标题】:Mapstruct generated classes are not found if the application is run from IntelliJ IDEA如果从 IntelliJ IDEA 运行应用程序,则找不到 Mapstruct 生成的类
【发布时间】:2020-01-29 16:09:50
【问题描述】:

我有一个使用 Mapstruct 1.3.0.Final 的 Gradle 4.8.1 构建的基于 Java 11 的应用程序。我使用 IntelliJ IDEA Ultimate 2019.2.3 进行开发。

问题:

如果我从 IntelliJ IDEA 启动该应用程序将无法运行,但是使用 Gradle 构建它时它可以运行。

当我从 IntelliJ 启动应用程序时,运行时出现以下错误:

ClassNotFoundException: Cannot find implementation for com.mycompany.MyMapper
    at org.mapstruct.factory.Mappers.getMapper(Mappers.java:75)
    at org.mapstruct.factory.Mappers.getMapper(Mappers.java:58)

我的项目设置:

我使用了另外一种注释处理工具——Lombok,它工作得很好。总之,我将它们放在我的依赖项中,如下所示:

compileOnly('org.projectlombok:lombok:1.18.10')
annotationProcessor('org.projectlombok:lombok:1.18.10')
compile('org.mapstruct:mapstruct:1.3.0.Final')
annotationProcessor('org.mapstruct:mapstruct-processor:1.3.0.Final')

如何重现:从需要使用 Mapstruct 生成的类的 IntelliJ UI 开始单元测试就足够了。

问题:如何让 IntelliJ IDEA 正确应用 Mapstruct 标注处理器?

我的尝试: 我在 StackOveflow 和 on GitHub 上遇到过类似的问题。不幸的是,他们没有帮助。他们要么使用旧版本的 lib、旧 JVM,要么只是解决方案不起作用。

【问题讨论】:

  • 您是否在“设置/首选项 | 构建、执行、部署 | 构建工具 | Gradle”中设置了“使用 Gradle 构建和运行”

标签: java intellij-idea annotation-processing mapstruct


【解决方案1】:

请在“Settings/Preferences | Build, Execution, Deployment | Build Tools | Gradle”中设置“Build and Run using Gradle”

【讨论】:

  • 感谢您的回答!为什么在处理 Gradle 项目时这不是默认的 IDE 设置?
猜你喜欢
  • 1970-01-01
  • 2022-11-23
  • 2023-03-24
  • 2016-03-15
  • 2020-05-12
  • 2011-12-24
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多