简体   繁体   English

如果从 IntelliJ IDEA 运行应用程序,则找不到 Mapstruct 生成的类

[英]Mapstruct generated classes are not found if the application is run from IntelliJ IDEA

I have a Java 11 based application built with Gradle 4.8.1 which uses Mapstruct 1.3.0.Final.我有一个使用 Gradle 4.8.1 构建的基于 Java 11 的应用程序,它使用 Mapstruct 1.3.0.Final。 I use IntelliJ IDEA Ultimate 2019.2.3 for development.我使用 IntelliJ IDEA Ultimate 2019.2.3 进行开发。

Problem:问题:

The application does't work if I start it from IntelliJ IDEA, however it works when it is built with Gradle.如果我从 IntelliJ IDEA 启动该应用程序,它就无法工作,但是当它使用 Gradle 构建时,它就可以工作。

I get the following error in run time when I start the app from IntelliJ:当我从 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)

My project setup:我的项目设置:

I use one more annotation processing tool - Lombok which works fine.我使用了另外一种注释处理工具——Lombok,它工作得很好。 All together I have them in my dependencies like this:总之,我将它们放在我的依赖项中,如下所示:

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')

How to reproduce: It is enough to start a unit test from IntelliJ UI that requires a class generated with Mapstruct.如何重现:从需要使用 Mapstruct 生成的 class 的 IntelliJ UI 开始单元测试就足够了。

Question: How to make IntelliJ IDEA correctly apply Mapstruct annotation processors?问题:如何让 IntelliJ IDEA 正确应用 Mapstruct 注释处理器?

What I have tried: I went through similar issues on StackOveflow and on GitHub .我尝试过的:我在 StackOveflow 和GitHub 上遇到了类似的问题。 Unfortunately, they didn't help.不幸的是,他们没有帮助。 They are either using old versions of the lib, an old JVM or simply the solutions don't work.他们要么使用旧版本的 lib,旧的 JVM,要么只是解决方案不起作用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM