Kristopher Noronha
Kristopher Noronha

Reputation: 157

Heroku app refuses to start up as it cannot load kotlin.jvm.internal.Intrinsics

I have a multi module project. One module is an android app and one is a spring-boot based server that I'm trying to run on Heroku. I first setup the android app and then added the Heroku module using directions on their site. The server runs fine locally in IntelliJ (as an application), but when deployed to Heroku, or run locally via heroku local web it crashes on startup:

Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) 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:50) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) Caused by: java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics at com.kristoph3r.videocallmyfriends.server.Application$Companion.main(Application.kt) at com.kristoph3r.videocallmyfriends.server.Application.main(Application.kt) ... 8 more Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:419) at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) at java.lang.ClassLoader.loadClass(ClassLoader.java:352) ... 10 more

The server code (and build.gradle, etc) is adapted from another Heroku app I've written (cloned from one of their example projects and modified), and that app runs fine on Heroku/locally in IntelliJ/locally using heroku local web. Not sure what additional information is required to figure this out. These are my build.gradle files:

Root project:

buildscript {
    ext.kotlin_version = '1.3.70'
    ext.spring_boot_version = '1.5.3.RELEASE'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task stage(dependsOn: [':server:stage'])

Server module:

apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'

bootRepackage {
    mainClassName = 'com.kristoph3r.videocallmyfriends.server.Application'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

task stage(dependsOn: ['build', 'clean']) {
    group = 'application'
}

build.mustRunAfter clean

jar {
    archiveBaseName = 'server'
    archiveVersion = '1.0'
}

Things I have tried so far:

One note is that my working project doesn't have the "stage" task configured, and yet builds and runs fine, while this project refuses to build on Heroku without the stage task. However, the Heroku documentation states that they trigger the stage task to build the app, so I'm not sure if the difference matters.

Upvotes: 0

Views: 301

Answers (1)

Kristopher Noronha
Kristopher Noronha

Reputation: 157

A spring boot upgrade and a lot of resulting changes in the server build.gradle fixed it (although my existing project still works on the old spring-boot version - quite a mystery!)

In the root project, inside buildscript, I changed the spring boot version:

    ext.spring_boot_version = '2.2.5.RELEASE'

In the server module:

Added the spring dependency management plugin:

apply plugin: 'io.spring.dependency-management'

Added a dependencyManagement section:

dependencyManagement {
    imports {
        mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
    }
}

For some reason (a quirk of spring boot?) I had to add another Kotlin dependency:

    implementation "org.jetbrains.kotlin:kotlin-reflect"

And finally had to replace bootRepackage with springBoot:

springBoot {
    mainClassName = 'com.krist0ph3r.videocallmyfriends.server.Application'
}

Upvotes: 0

Related Questions