mapstruct-examples
mapstruct-examples copied to clipboard
Kotin class java.lang.ClassNotFoundException
I built example project Kotlin Gradle but it showed error "class not found exception"
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: Cannot find implementation for org.mapstruct.example.kotlin.converter.PersonConverter
at org.mapstruct.factory.Mappers.getMapper(Mappers.java:61)
at org.mapstruct.example.kotlin.MainKt.main(Main.kt:10)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.ClassNotFoundException: Cannot find implementation for org.mapstruct.example.kotlin.converter.PersonConverter
at org.mapstruct.factory.Mappers.getMapper(Mappers.java:75)
at org.mapstruct.factory.Mappers.getMapper(Mappers.java:58)
... 6 more
Can you please tell us how you are building the project?
Asking because our CI is green. See https://github.com/mapstruct/mapstruct-examples/runs/767089987
I have the same problem using the Mapstruct-Kotlin-Maven example. I use Intellij as IDE.
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: Cannot find implementation for org.mapstruct.example.kotlin.converter.PersonConverter
at org.mapstruct.factory.Mappers.getMapper(Mappers.java:61)
at org.mapstruct.example.kotlin.MainKt.main(Main.kt:10)
Hi, same problem here... JDK 16, Kotlin 1.5.21, Maven, IntelliJ IDEA...
Problem is in KAPT incompatibility with newer versions of JDK https://youtrack.jetbrains.com/issue/KT-45545
Facing the same problem with: JDK 11, Kotlin 1.43.2, MapStruct 1.5.0.Beta1, IntelliJ IDEA
My build.gradle
plugins {
id 'java'
...
id 'org.jetbrains.kotlin.jvm' version "1.4.32"
id 'org.jetbrains.kotlin.plugin.spring' version "1.4.32"
id 'org.jetbrains.kotlin.plugin.jpa' version "1.4.32"
id "org.jetbrains.kotlin.kapt" version "1.4.32"
}
dependencies {
...
implementation 'org.mapstruct:mapstruct:1.5.0.Beta1'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.0.Beta1'
testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.0.Beta1'
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "11"
}
}
Tried launching with org.gradle.jvmargs='--illegal-access=permit', result is the same
EDIT
changed dependencies part to:
dependencies {
...
implementation 'org.mapstruct:mapstruct:1.5.0.Beta1'
kapt 'org.mapstruct:mapstruct-processor:1.5.0.Beta1'
kapt 'org.mapstruct:mapstruct-processor:1.5.0.Beta1'
}
And now it works, apologies for the confusion. org.gradle.jvmargs='--illegal-access=permit' is not required