tschuchortdev / kotlin-compile-testing

A library for testing Kotlin and Java annotation processors, compiler plugins and code generation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compatibility Issues with Kotlin version 1.6.20-dev-997

irenedea opened this issue · comments

I am using the Kotlin version 1.6.20-dev-997 (the latest bootstrap build, which is built about every two weeks from master) and kotlin-compile-testing version 1.4.4.

Unfortunately, this update has caused some compatibility issues (there is a NoSuchMethodError when I run my test for my Kotlin compiler plugin):

java.lang.NoSuchMethodError: org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments.setStrictJavaNullabilityAssertions(Z)V
	at com.tschuchort.compiletesting.KotlinCompilation$commonK2JVMArgs$1.invoke(KotlinCompilation.kt:328)
	at com.tschuchort.compiletesting.KotlinCompilation$commonK2JVMArgs$1.invoke(KotlinCompilation.kt:293)
	at com.tschuchort.compiletesting.AbstractKotlinCompilation.commonArguments(AbstractKotlinCompilation.kt:115)
	at com.tschuchort.compiletesting.KotlinCompilation.commonK2JVMArgs(KotlinCompilation.kt:293)
	at com.tschuchort.compiletesting.KotlinCompilation.stubsAndApt(KotlinCompilation.kt:453)
	at com.tschuchort.compiletesting.KotlinCompilation.compile(KotlinCompilation.kt:636)

To reproduce the error, include the following in build.gradle.kts and try to run some tests:

plugins {
    ...
    kotlin("jvm") version "1.6.20-dev-997" // Kotlin
}

repositories {
    ...
    maven {
      url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") // Maven repository for bootstrap builds
    }
  }

dependencies {
...
  testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
  testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.4")
}

KCT version 1.4.4 only supports Kotlin version 1.5.30. The KCT internals are tightly coupled to the kotlin-compiler-embeddable which does not have a stable API and can change at any time, thus we can not support multiple Kotlin versions for a given version of KCT. You always have to use the Kotlin version of the kotlin-compiler-embeddable that is bundled with KCT or else you risk these runtime incompatibility errors. Unfortunately, there's not much I can do about that.

My guess is you probably overwrote the kotlin-compiler-embeddable transitive dependency with the line testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable").