3

I do have a Kotlin Spring Boot application with kotlin.gradle

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")

So stdlib is included in the project.

In my fat jar I can see the lib too under the path BOOT-INF/lib

kotlinstdlib

But somehow when I java -jar app.jar

I'm getting:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
        at dev.nsud.ApplicationKt.main(Application.kt)
        ... 8 more
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 9 more

Somehow this perfectly works in Intellij IDEA.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Igor Kustov
  • 787
  • 1
  • 8
  • 21

1 Answers1

0

If you wanna create a fat jar you have to add manifest attributes to your build.gradle and it should look like this,

jar {
    manifest {
        attributes 'Main-Class': 'com.your.main.class.Name'
    }

    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

If you already have your manifest attributes in place I assume the issue is with the way you have defined from as it needs to be configurations.runtimeClasspath instead configurations.compile

NOTE: It'll be great if I can see your full build.gradle to understand the issue further

Panduka DeSilva
  • 817
  • 9
  • 12