添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Bundled Kotlin stdlib preferred over classpath dependencies #15020

Closed
@DanielThomas

Description

@DanielThomas

We ran into a compatibility issue with a plugin that used okhttp3/okio on the classpath caused by the bundled Kotlin version on the classpath:

Caused by: java.lang.NoSuchMethodError: kotlin.collections.ArraysKt.copyInto([B[BIII)[B
        at okio.Segment.writeTo(Segment.kt:169)
        at okio.Segment.compact(Segment.kt:152)
        at okio.Buffer.write(Buffer.kt:1842)
        at okio.Buffer.read(Buffer.kt:1854)
        at okio.Buffer.writeAll(Buffer.kt:1642)
        at okio.Options$Companion.buildTrieRecursive(Options.kt:187)
        at okio.Options$Companion.buildTrieRecursive(Options.kt:174)
        at okio.Options$Companion.buildTrieRecursive$default(Options.kt:113)
        at okio.Options$Companion.of(Options.kt:72)
        at okhttp3.internal.Util.<clinit>(Util.kt:71)
        at okhttp3.internal.concurrent.TaskRunner.<clinit>(TaskRunner.kt:309)
        at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:41)
        at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:47)
        at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.kt:471)

That means when developing plugins in Kotlin we have to be very aware of not exceeding stdlib compatibility for the bundled Gradle Kotlin standard library version.

Expected Behavior

The buildscript classpath should win over any default dependencies.

Current Behavior

Default dependencies win over buildscript classpath dependencies.

Context

It makes maintaining plugins difficult and makes adoption of later Kotlin features difficult, causing us to resort to shading to provide classpath isolation, which comes with its own problems.

Steps to Reproduce

Take the following build:

buildscript {
    repositories {
        mavenCentral()
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
// Kotlin 1.x class
println Class.forName("kotlin.SynchronizedLazyImpl").package.implementationVersion
// Kotlin 1.4-only class
println Class.forName("kotlin.properties.PropertyDelegateProvider").package.implementationVersion

Run ./gradlew help and note the output:

1.3.72-release-468 (1.3.72)
1.4.10-release-411 (1.4.10)

Your Environment

Gradle 6.7

Activity

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

Metadata

Assignees

No one assigned

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions