Tests fail just on upgrading Kotlin from 1.4 to 1.5

I have a slightly old but working build.gradle.kts with Gradle 7.1.1 and Kotlin 1.4.21 - all my tests pass when I run gradle test:

import com.jfrog.bintray.gradle.BintrayExtension
import org.jetbrains.dokka.gradle.DokkaTask

plugins {
    // Apply the Kotlin JVM plugin to add support for Kotlin.
    id("org.jetbrains.kotlin.jvm") version "1.4.21"

    // For documentation
    id("org.jetbrains.dokka") version "0.10.1"

    // Apply the java-library plugin for API and implementation separation.
    // For Maven repository upload
    id("com.jfrog.bintray") version "1.8.4"

group = "com.reddove"
version = "0.1.0"

repositories {

dependencies {
    // Align versions of all Kotlin components

    // Use the Kotlin JDK 8 standard library.



    // Use the Kotlin test library.

    // Use the Kotlin JUnit integration.

    // additional dependencies used in tests

sourceSets {
    main {
        java {
    test {
        java {

tasks.withType<Test> {
    testLogging {
        events("passed", "skipped", "failed")
        showStandardStreams = true

tasks.withType(Jar::class) {
    manifest {
        attributes["Manifest-Version"] = "1.0"
        attributes["Implementation-Title"] = "Red Dove CFG library"
        attributes["Implementation-Version"] = "0.1.0"
        attributes["Implementation-Vendor"] = "Red Dove Consultants Limited"
        attributes["Implementation-Vendor-Id"] = "com.reddove"

tasks.withType(DokkaTask::class) {
    outputFormat = "html"
    outputDirectory = "$buildDir/dokka"
    // add other Dokka configuration here

fun prop(s: String) = project.findProperty(s) as String?

publishing {
    publications.register("publication", MavenPublication::class) {

    repositories {
        maven {
            metadataSources {

val publication by publishing.publications

bintray {
    user = prop("bintrayUser")
    key = prop("bintrayAPIKey")
    publish = true
    override = true
    pkg(delegateClosureOf<BintrayExtension.PackageConfig> {
        repo = "public"
        name = "com.reddove.config"
        userOrg = "reddove"
        websiteUrl = "https://www.red-dove.com"
        vcsUrl = "https://github.com/vsajip/ktlib"

Ignoring the JFrog/bintray stuff which is of course now obsolete, I only changed the Kotlin version from 1.4.21 to 1.5.21 (in two places - the id("org.jetbrains.kotlin.jvm") version "1.4.21" line and the implementation("org.jetbrains.kotlin:kotlin-reflect:1.4.21") line. But now gradle test fails 33 of 35 tests, all because of java.lang.NoClassDefFoundError at various points in my test.kt. What am I doing wrong? The exception is caused here:

java.lang.NoClassDefFoundError: Could not initialize class com.reddove.config.ConfigKt
	at com.reddove.config.Config.<init>(config.kt:2475)

Has something fundamental changed from 1.4 to 1.5 to cause this problem? In config.kt, the offending line is the one which sets up stringConverter:

class Config() {
    // stuff omitted
    var stringConverter: StringConverter = defaultStringConverter

and defaultStringConverter is defined further up the file as

typealias StringConverter = (String, Config) -> Any

val defaultStringConverter = fun(s: String, cfg: Config) : Any {
    // details omitted

I’m totally guessing, but it could be because of changed JVM backend in 1.5. Does it help to compile all relevant modules with -Xuse-old-backend compiler argument?

See What's new in Kotlin 1.5.0 | Kotlin

Thanks for the suggestion; it made no difference. I added

tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile> {
  kotlinOptions.useOldBackend = true

to build.gradle.kts and updated the Kotlin version to 1.5.21 - it seemed to build OK, as beore, but I get the same result with gradle test :frowning:

Ok, it’s hard to say more without investigation. Can you please create an issue at http://kotl.in/issue with some version of your project to reproduce? BTW visibility of attachment can be restricted to “jetbrains-team”.

I had an exception when switching from 1.51 to 1.52 on a JS project. On JVM and multiplatform platform projects it seems that a similar issue occurs earlier (might be your switch to 1.5 then). I had the exception:

In the log file:
Caused by: java.lang.ClassNotFoundException: org.antlr.v4.runtime.Lexer
… 191 more

Different but similar. The solution was then to prioritize the repos to download the plugins differently, since with standard configuration, there seem to be problems from time to time with the POM coming from the gradle repo. You can find some info, how to set up priority for plugin repos here:


pluginManagement {
    repositories {

in the settings.gradle.kts

and rebuild the gradle project to given mavenCentral() priority over the gradle repo

this worked for me then. Maybe it might help you


1 Like