Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotin class java.lang.ClassNotFoundException #84

Open
at-tantv opened this issue Jul 5, 2020 · 5 comments
Open

Kotin class java.lang.ClassNotFoundException #84

at-tantv opened this issue Jul 5, 2020 · 5 comments

Comments

@at-tantv
Copy link

at-tantv commented Jul 5, 2020

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

@filiphr
Copy link
Member

filiphr commented Jul 5, 2020

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

@Jozott00
Copy link

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)

@otoman
Copy link

otoman commented Jul 28, 2021

Hi, same problem here... JDK 16, Kotlin 1.5.21, Maven, IntelliJ IDEA...

@otoman
Copy link

otoman commented Jul 29, 2021

Problem is in KAPT incompatibility with newer versions of JDK https://youtrack.jetbrains.com/issue/KT-45545

@fire-papaya
Copy link

fire-papaya commented Jul 31, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants