简体   繁体   中英

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. I use IntelliJ IDEA Ultimate 2019.2.3 for development.

Problem:

The application does't work if I start it from IntelliJ IDEA, however it works when it is built with Gradle.

I get the following error in run time when I start the app from 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. 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.

Question: How to make IntelliJ IDEA correctly apply Mapstruct annotation processors?

What I have tried: I went through similar issues on StackOveflow and on 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.

Please set "Build and Run using Gradle" in "Settings/Preferences | Build, Execution, Deployment | Build Tools | Gradle"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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