Gradle Project: java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics

前端 未结 8 1516
抹茶落季
抹茶落季 2020-12-14 14:50

I\'m working on a Java project and within this project I did my first try with Kotlin. I started converting some classes to Kotlin with the JavaToKoltin converter provided i

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 15:27

    This error is likely due to the fact that the simple jar task doesn’t take all its runtime dependencies.

    From gradle documentation, In your build.gradle.kts you can either create a "fatJar" task or add that to your jar task:

    tasks.withType {
        // Otherwise you'll get a "No main manifest attribute" error
        manifest {
            attributes["Main-Class"] = "com.example.MainKt"
        }
    
        // To add all of the dependencies
        from(sourceSets.main.get().output)
    
        dependsOn(configurations.runtimeClasspath)
        from({
            configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
        })
    }
    

提交回复
热议问题