Skip to content

Conversation

@hugoncosta
Copy link

Address #9032 by setting apiVersion and languageVersion to 2.0. This ensures that the code can be compiled with Kotlin 2.2.0+ but users as low as 1.9.0 are able to run this without being forced to update. For reference, 2.2.0 supports compilation as low as 1.6.0.

Compiled locally, seems to work fine, but my laptop is not setup to compile the Android modules btw

Copy link
Collaborator

@yschimke yschimke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pointless as is, unless you also update okio. OkHttp might be compatible, but it relies on very recent versions of Okio which arent.

Can you start there and we can happily follow their lead. Mostly the same maintainers I know.

https://github.com/square/okio/blob/master/build.gradle.kts

@hugoncosta
Copy link
Author

Sorry about that - not really used to these workflows + I don't have an Android SDK on my machine. I think this should be it 🤞

@hugoncosta hugoncosta force-pushed the kotlin2.0Compatibility branch from 5de0707 to 7581937 Compare August 30, 2025 16:28
@hugoncosta
Copy link
Author

I think I have found an easier path, and especially one that doesn't require us to change much - the source code is already 2.0 compatible, only the tests aren't, and they don't need to be, so why bother? The change is now focusing only on "main" source sets, leaving the tests to use any 2.0+ feature.

Comment on lines +198 to +209
// Configure all projects' source sets (jvm and kmp)
plugins.matching { it.javaClass.name.startsWith("org.jetbrains.kotlin") }.configureEach {
kotlinExtension.sourceSets {
// Exclude all test source sets (containing Test)
matching { !it.name.contains("Test", ignoreCase = true) }.all {
languageSettings {
apiVersion = "2.0"
languageVersion = "2.0"
}
}
}
}
Copy link
Contributor

@Goooler Goooler Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Configure all projects' source sets (jvm and kmp)
plugins.matching { it.javaClass.name.startsWith("org.jetbrains.kotlin") }.configureEach {
kotlinExtension.sourceSets {
// Exclude all test source sets (containing Test)
matching { !it.name.contains("Test", ignoreCase = true) }.all {
languageSettings {
apiVersion = "2.0"
languageVersion = "2.0"
}
}
}
}
tasks.withType<KotlinCompile>().configureEach {
if (name.contains("test")) return@configureEach // Skip test source sets.
compilerOptions {
// Pin language level to 2.0 to ensure compatibility with older Gradle versions and other libraries that depend on okhttp.
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
languageVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0
apiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0
}
}
@yschimke
Copy link
Collaborator

yschimke commented Oct 2, 2025

I'll wait for square/okio#1690 to land before this

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

Labels

None yet

3 participants