Skip to content

Kotlin runtime not completely excluded #585

@mvilliger

Description

@mvilliger

We have an IntelliJ plugin written in Kotlin. Our build.gradle.kts looks like this:

plugins {
    id("java")
    id("idea")
    id("org.jetbrains.intellij") version "0.6.5"
    kotlin("jvm") version "1.4.21-2"
}

dependencies {
    ...
    implementation(kotlin("stdlib-jdk8"))
    ...
}

intellij {
    version = "IU-2020.1.2"
    setPlugins(...)
}

tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions {
        jvmTarget = "11"
        apiVersion = "1.4"
        languageVersion = "1.4"
    }
}

When using Kotlin 1.4 with an older IntelliJ version containing Kotlin 1.3 (like above version 2020.1.2) the build complains about mixed versions:

Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    .gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.4.21-2/fc405f82531d86896a20e9aab54129dc59f86920/kotlin-stdlib-jdk8-1.4.21-2.jar (version 1.4)
    .gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2020.1.2/13c0df9eec16f4c4e6e6a4fb86987e616b7b038f/ideaIU-2020.1.2/lib/kotlin-reflect-1.3.70.jar (version 1.3)
    .gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.4.21-2/813d63537c9df0ee0184f2fada6bc040b1328395/kotlin-stdlib-jdk7-1.4.21-2.jar (version 1.4)
    .gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.21-2/e9840ab2db3095cf168d5425899be9fc97f848ca/kotlin-stdlib-1.4.21-2.jar (version 1.4)
    .gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.21-2/3c1c0910bfba8bdb1a14303002d162b96a3aad11/kotlin-stdlib-common-1.4.21-2.jar (version 1.4)
Consider providing an explicit dependency on kotlin-reflect 1.4 to prevent strange errors
Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

As you can see it only complains for the kotlin-reflect jar file. The 1.3 kotlin-stdlib jars (which exist in the same location within 2020.1.2) are not part of the classpath.

As far as I can see this is because the gradle-intellij-plugin has a mechanism to exclude the Kotlin runtime if necessary (see org.jetbrains.intellij.dependency.IdeaDependency#collectJarFiles). It uses IdeaDependencyManager#isKotlinRuntime to detect if a jar belongs to the Kotlin runtime. But this method checks using 'kotlin-reflect' == name while it uses name.startsWith('kotlin-stdlib'). In my cases name was 'kotlin-reflect-1.3.70' which explains why it is not detected and therefore not excluded.

Maybe this check should use startsWith as well? Maybe the same for the 'kotlin-runtime' check before?
Or is our setup wrong?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions