Skip to content

Commit

Permalink
fix(compatibility): return support for Kotlin's -Xjdk-release=18+ in …
Browse files Browse the repository at this point in the history
…JDK 23+

- Define JRE_23 and KOTLIN_2_0_20 constants
- Update jdk-release conditions for Kotlin versions 2.0 and above

More info on the original issue:
- https://bugs.openjdk.org/browse/JDK-8331027
- https://youtrack.jetbrains.com/issue/KT-67668

Signed-off-by: Art Shendrik <artyom.shendrik@gmail.com>
  • Loading branch information
amal committed Nov 18, 2024
1 parent 7868761 commit 3c40c9e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[//]: # (Removed, Added, Changed, Fixed, Updated)

### Fixed
- return support for Kotlin's `-Xjdk-release=18+` in JDK 23+.
- fix bundled shrinker loading.

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ internal const val JRE_17 = 11

internal const val JRE_21 = 21

internal const val JRE_23 = 23

// https://www.oracle.com/java/technologies/downloads/
private const val LTS_JDK_VERSION = JRE_21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ internal val KOTLIN_1_9_20 = KotlinVersion(1, 9, 20)

internal val KOTLIN_2_0 = KotlinVersion(2, 0, 0)

internal val KOTLIN_2_0_20 = KotlinVersion(2, 0, 20)


@Volatile
internal var KOTLIN_PLUGIN_VERSION: KotlinVersion = KotlinVersion.CURRENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,30 @@ internal fun KotlinCommonOptions.setupKotlinOptions(
// Only apply jdk-release in JVM (non-Android) builds.
// https://github.com/slackhq/slack-gradle-plugin/commit/8445dbf943c6871a27a04186772efc1c42498cda.
!isAndroid &&
// Do not use when compiled against the current JDK version (useless).
// Don't use when compiled against the current JDK version (useless).
jvmTargetInt != JRE_VERSION &&
// Somehow, jdk-release fails with kotlin lang 2.0 and Kotlin 1.9.
(!kotlin20orUpper || kotlinPluginVersion >= KOTLIN_2_0)
( // Somehow, jdk-release fails with kotlin lang 2.0 and Kotlin 1.9.
!kotlin20orUpper ||
kotlinPluginVersion >= KOTLIN_2_0 && kotlinPluginVersion < KOTLIN_2_0_20
)

// ct.sym is broken for -Xjdk-release=18+
// ct.sym is broken for -Xjdk-release=18+ with JDK 18..22.
// https://bugs.openjdk.org/browse/JDK-8331027
// https://youtrack.jetbrains.com/issue/KT-67668
// TODO: Verify ct.sym fix later.
val broken = jvmTargetInt > JRE_17
if (useJdkRelease && broken && !BROKEN_JDK_RELEASE_LOGGED) {
val jdkReleaseIsBroken = jvmTargetInt in (JRE_17 + 1) until JRE_23 &&
JRE_VERSION < JRE_23
if (useJdkRelease && jdkReleaseIsBroken && !BROKEN_JDK_RELEASE_LOGGED) {
BROKEN_JDK_RELEASE_LOGGED = true
conf.project.logger.e(
"-Xjdk-release is broken for JRE 18..21, so it is disabled! \n",
"-Xjdk-release is broken for JRE 18..21 with JDK 18..22" +
", so it is disabled! \n",
"https://bugs.openjdk.org/browse/JDK-8331027 \n",
"https://youtrack.jetbrains.com/issue/KT-67668",
)
}

// Compile against the specified JDK API version, similarly to javac's `-release`.
if (useJdkRelease && !broken) {
if (useJdkRelease && !jdkReleaseIsBroken) {
compilerArgs.add("-Xjdk-release=$jvmTarget")

// TODO: Allow -Xjdk-release=1.6 with -jvm-target 1.8 for Kotlin 2.0+
Expand Down

0 comments on commit 3c40c9e

Please sign in to comment.