Skip to content

Kotin class java.lang.ClassNotFoundException  #84

Open

Description

@at-tantv

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

Activity

  1. filiphr commented on Jul 5, 2020

    @filiphr
    Member

    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

  2. Jozott00 commented on Jul 14, 2021

    @Jozott00

    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)
    
  3. otoman commented on Jul 28, 2021

    @otoman

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

  4. otoman commented on Jul 29, 2021

    @otoman

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

  5. fire-papaya commented on Jul 31, 2021

    @fire-papaya

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions