Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin runtime not completely excluded #585

Closed
mvilliger opened this issue Jan 4, 2021 · 16 comments
Closed

Kotlin runtime not completely excluded #585

mvilliger opened this issue Jan 4, 2021 · 16 comments
Assignees
Milestone

Comments

@mvilliger
Copy link

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?

@mvilliger
Copy link
Author

Quick update: Adding an explicit dependency to kotlin-reflect 1.4 as suggested by the build output makes no difference. The classpath still contains mixed versions.

@mvilliger
Copy link
Author

Any news on this?

@zolotov
Copy link
Member

zolotov commented Feb 24, 2021

Hi @mvilliger, sorry for the silence. No news so far. Your suggestion about startsWith sounds reasonable but I wonder if there any better solution for that, than just excluding kotlin jars by some exclusions list.

@mvilliger
Copy link
Author

No problem. Thanks for your answer. Any better solution is of course welcome as well :)

@mvilliger
Copy link
Author

But maybe it is better to first provide a fix for the current solution (short term) until we can come up with some better solution for the future?

@zolotov
Copy link
Member

zolotov commented Mar 10, 2021

makes sense, I'll take a look in couple days

@zolotov
Copy link
Member

zolotov commented Mar 11, 2021

I couldn't recreate the warning but the change seems reasonable anyway. I've pushed it. The snapshot will be available in couple hours I think

@mvilliger
Copy link
Author

Thanks @zolotov I will test it the next days. Coming back to you.

@mvilliger
Copy link
Author

@zolotov I can confirm that the issue is fixed in version 0.8.0-SNAPSHOT. Thank you very much!

And I just found #503 which might be related to this issue here and may be fixed as well?

Unfortunately we hit issue #606 with the new version which seemed to work in the version 0.6.5 we used before.
So this prevents us from upgrading for the moment.

@zolotov
Copy link
Member

zolotov commented Mar 14, 2021

Thank you! I'll investigate #606 before publishing 0.7.3

@L2jLiga
Copy link

L2jLiga commented Mar 15, 2021

Hi @zolotov, does 99d2a48 fixes #612 as well?

Just checked on my local machine, issue was not fixed, my steps:

  1. Clean all gradle cache
  2. Change plugin version to "0.8.0-SNAPSHOT"
  3. Run gradlew build
Console output

Task :compileKotlin
w: Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath
w: C:\Users\user.gradle\caches\modules-2\files-2.1\com.jetbrains.intellij.idea\ideaIU\LATEST-EAP-SNAPSHOT\14ed4e191a397850ef06d2c35c842ded7cdda455\ideaIU-LATEST-EAP-SNAPSHOT\lib\kotlin-stdlib-jdk8.jar: Library has Kotlin runtime bundled into it

@mvilliger
Copy link
Author

@zolotov Thank you!

@zolotov
Copy link
Member

zolotov commented Mar 15, 2021

@L2jLiga thanks for checking, I'll look into that one too

@zolotov zolotov added this to the 0.7.3 milestone Apr 21, 2021
@zolotov zolotov self-assigned this Apr 21, 2021
@AlexPl292
Copy link
Member

I still experience this issue with 0.7.3. Is this expected?

w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    /Users/alex.plate/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.71/4defc79915cf4f78b49bbc4a8f1e80e87767a5b/kotlin-stdlib-jdk8-1.3.71.jar (version 1.3)
    /Users/alex.plate/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.71/9180d3aec3f0b2ea6ef0dcf01b464a6e2219e381/kotlin-stdlib-jdk7-1.3.71.jar (version 1.3)
    /Users/alex.plate/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.71/898273189ad22779da6bed88ded39b14cb5fd432/kotlin-stdlib-1.3.71.jar (version 1.3)
    /Users/alex.plate/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/LATEST-EAP-SNAPSHOT/64338e7ae817fccadb3c201ea67e4cf1efb9e4b2/ideaIC-LATEST-EAP-SNAPSHOT/lib/kotlin-reflect-1.4.32.jar (version 1.4)
    /Users/alex.plate/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.71/e71c3fef58e26affeb03d675e91fd8abdd44aa7b/kotlin-stdlib-common-1.3.71.jar (version 1.3)
    ```

@zolotov
Copy link
Member

zolotov commented Apr 28, 2021

@AlexPl292 likely yes, see #612

@JakkuSakura
Copy link

I'm still having this problem

w: Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath
w: /home/jack/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2021.2/b0727ceddea2b62b16825db9308e14a470198e7f/ideaIC-2021.2/lib/kotlin-stdlib-jdk8.jar: Library has Kotlin runtime bundled into it
# IntelliJ Platform Artifacts Repositories
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html

pluginGroup = org.bytecamp.program_repair.astor_plugin
pluginName = IntelliJ Idea Astor Plugin
pluginVersion = 0.2.2

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild = 202
pluginUntilBuild = 212.*

# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions = 2020.2.4

platformType = IC
platformVersion = 2021.2
# Bug: Using platformLocalPath does not work with java plugin https://youtrack.jetbrains.com/issue/IDEA-274934
#platformLocalPath = downloaded/ideaIC-2021.2
platformDownloadSources = true
#jreVersion =

# Opt-out flag for bundling Kotlin standard library.
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
kotlin.stdlib.default.dependency = false
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

fun properties(key: String) = project.findProperty(key).toString()

plugins {
    // Java support
    id("java")
    // Kotlin support
    id("org.jetbrains.kotlin.jvm") version "1.5.10"
    // gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
    id("org.jetbrains.intellij") version "1.1.2"
    // gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
    id("org.jetbrains.changelog") version "1.1.2"
}

group = properties("pluginGroup")
version = properties("pluginVersion")
//
// Configure project's dependencies
repositories {
    mavenCentral()
}
dependencies {
    implementation("com.google.code.gson:gson:2.8.7")


    testImplementation(platform("org.junit:junit-bom:5.7.2"))
    testImplementation("org.junit.jupiter:junit-jupiter:5.7.2")

}


// Configure gradle-intellij-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
    pluginName.set(properties("pluginName"))

    if (properties("platformVersion") != "null") {
        version.set(properties("platformVersion"))
    } else {
        localPath.set(properties("platformLocalPath"))
    }
    type.set(properties("platformType"))
    downloadSources.set(properties("platformDownloadSources").toBoolean())
    updateSinceUntilBuild.set(true)


    plugins.set(listOf("java"))
}

// Configure gradle-changelog-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-changelog-plugin
changelog {
    version = properties("pluginVersion")
    groups = emptyList()
}

tasks {
    // Set the compatibility versions to 1.8
    withType<JavaCompile> {
        sourceCompatibility = "1.8"
        targetCompatibility = "1.8"
    }
    withType<KotlinCompile> {
        kotlinOptions.jvmTarget = "1.8"
    }

    patchPluginXml {
        version.set(properties("pluginVersion"))
        sinceBuild.set(properties("pluginSinceBuild"))
        untilBuild.set(properties("pluginUntilBuild"))

        // Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
        pluginDescription.set(
            File(projectDir, "README.md").readText().lines().run {
                val start = "<!-- Plugin description -->"
                val end = "<!-- Plugin description end -->"

                if (!containsAll(listOf(start, end))) {
                    throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
                }
                subList(indexOf(start) + 1, indexOf(end))
            }.joinToString("\n").run { markdownToHTML(this) }
        )

        // Get the latest available change notes from the changelog file
        changeNotes.set(provider { changelog.getLatest().toHTML() })
    }

    runPluginVerifier {
        ideVersions.set(properties("pluginVerifierIdeVersions").split(',').map(String::trim).filter(String::isNotEmpty))
    }
    runIde {
        if (properties("jreVersion") != "null")
            jbrVersion.set(properties("jreVersion"))
        autoReloadPlugins.set(true)
    }
    buildSearchableOptions {
        if (properties("jreVersion") != "null")
            jbrVersion.set(properties("jreVersion"))
    }
    test {
        useJUnitPlatform()
        testLogging {
            events("passed", "skipped", "failed")
        }
    }
    publishPlugin {
        dependsOn("patchChangelog")
        token.set(System.getenv("PUBLISH_TOKEN"))
        // pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
        // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
        // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
        channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first()))
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants