Skip to content

Kotlin 2.1.20 support #4821

@gyoge0

Description

@gyoge0

Please describe the feature you'd like to see including any solutions in mind if you have any
Add support for Kotlin 2.1.20. There is a PR existing for this (#4816) but the builds seem to break.

Building this on my end gives errors regarding the java and application plugins from gradle:

e: ❌ 'application' Plugin Incompatible with 'org.jetbrains.kotlin.multiplatform' Plugin
'application' (also applies 'java' plugin) Gradle plugin is not compatible with 'org.jetbrains.kotlin.multiplatform' plugin.
Consider the new KMP/JVM binaries DSL as a replacement: https://kotl.in/jvm-binaries-dsl

It looks like it was deprecated in Kotlin 2.0.20. The build error does link to a fix, but it is marked with an experimental API.

Only two projects actually used the java or application plugins: the base Kotest project and kotest-framework-standalone. Removing the java plugin from the base project seems to fix it. kotest-framework-standalone has a more involved fix:

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
   id("kotest-jvm-conventions")
   alias(libs.plugins.shadowjar)
}

kotlin {
   jvm {
      @OptIn(ExperimentalKotlinGradlePluginApi::class)
      binaries {
         executable {
            mainClass.set("io.kotest.engine.launcher.MainKt")
         }
      }
   }
}

tasks {
   // for some reason, the `shadowJar` block can't be accessed here and I have
   // to get the task by it's type
   val shadowJar = withType<ShadowJar> {
      archiveClassifier.set(null as String?)
      archiveBaseName.set("kotest-framework-standalone-jvm")
      exclude("**/module-info.class")
      mergeServiceFiles()
      manifest {
         attributes(Pair("Main-Class", "io.kotest.engine.launcher.MainKt"))
      }
   }

   // same with the `startScripts` block
   withType<CreateStartScripts> {
      dependsOn(shadowJar)
   }
}

// dependencies below

Setting jvm.binaries.executable creates two new files, which are shell scripts to launch the executable jar:

build/jvm/scripts/kotest-framework-standalone
build/jvm/scripts/kotest-framework-standalone.bat

The jar task was part of the java-library and application plugins, and removing it does change the outputs:

-build/distributions/kotest-framework-standalone.tar
+build/distributions/kotest-framework-standalone-jvm.tar
-build/distributions/kotest-framework-standalone.zip
+build/distributions/kotest-framework-standalone-jvm.zip

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