Skip to content

Stop bundling kotlin-stdlib; compile against the IDE's Kotlin API version #539

Description

@SJrX

Background

IntelliJ Platform Gradle Plugin 2.19.0 changed two defaults:

  • kotlin.stdlib.default.dependency now defaults to false.
  • New default sandbox exclusions drop libraries the IDE already provides.

As a result, kotlin-stdlib was no longer bundled in the plugin. Our code is compiled with Kotlin 2.4.20, but it then ran against 2024.2's older bundled stdlib. 65 tests failed
with:

java.lang.NoSuchMethodError: 'kotlin.sequences.Sequence kotlin.sequences.SequencesKt.sequenceOf(java.lang.Object)'
at ...grammar.SequenceCombinator.parse(SequenceCombinator.kt:61)

Current workaround (in fix/intellij-platform-2.19.0)

These two lines are in gradle.properties. They are also in ci/release-branch-automation.Jenkinsfile, because that job regenerates gradle.properties.
kotlin.stdlib.default.dependency=true
org.jetbrains.intellij.platform.useDefaultSandboxExclusions=false
This brings back the 2.18.1 behaviour: kotlin-stdlib-2.4.20.jar is bundled. It also turns off the new exclusions for every other library the platform already provides, not just
the stdlib.

Why this should be removed

JetBrains advises against bundling the stdlib. The IDE always loads some kotlin.* classes from the platform, such as coroutines and function types, so a bundled stdlib gives
you a mix of two versions. Bundling also hid the fact that we use stdlib functions newer than our since-build (242) supports.

Proposed fix

  • Confirm the exact Kotlin version bundled with IntelliJ 2024.2.
  • In build.gradle.kts, set kotlin { compilerOptions { apiVersion / languageVersion } } to that version (KOTLIN_2_0).
  • Remove both properties from gradle.properties and the Jenkinsfile.
  • Fix any newer stdlib functions the compiler flags. sequenceOf(x) should fall back to the older multi-argument version on its own.
  • Check that the plugin zip no longer contains kotlin-stdlib and that all tests pass.

A quick spike showed that Kotlin 2.4.20 compiles the codebase with apiVersion/languageVersion = 2.0. The tests weren't run in that configuration.

Longer term

Kotlin 2.4 already warns: "Language version 2.0 is deprecated and its support will be removed in a future version of Kotlin." Once a Kotlin release drops 2.0, 242.x has two
choices:

  • Stay on the last Kotlin compiler that still supports 2.0.
  • Raise the since-build, for example by finally forking a newer release branch such as 262.x. A newer IDE ships a newer Kotlin, so the pin can move up.

Related: #537 (dependabot bump to 2.19.0).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions