-
Notifications
You must be signed in to change notification settings - Fork 657
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
Bump languageVersion/apiVersion to Kotlin 2.0 #5931
Conversation
✅ Deploy Preview for apollo-android-docs canceled.
|
import org.gradle.api.DomainObjectSet | ||
import org.gradle.api.Project | ||
|
||
internal class VariantWrapper(private val _wrapped: BaseVariant) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Gradle tests were failing with a crash when applying the Apollo Gradle plugin, due to this line throwing a NoClassDefFoundError
on com.android.build.gradle.api.BaseVariant
. After some digging I reckoned this was from using AndroidProject
which exposed BaseVariant
in its API. However, not sure why this causes a problem with K2 only - guessing the callsite's bytecode now references BaseVariant
which didn't happen with K1. Using a wrapper solves it.
@@ -123,3 +126,11 @@ dependencies { | |||
to.attribute(artifactType, ArtifactTypeDefinition.DIRECTORY_TYPE) | |||
} | |||
} | |||
|
|||
// Can't use apiVersion KOTLIN_2_0 when using languageVersion KOTLIN_1_9, which is the case here because we're using KSP 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is languageVersion
set to KOTLIN_1_9
? Is KSP overriding our default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure, but guessing yes, KSP must automatically switch to K1. Interestingly, if I set languageVersion.set(KotlinVersion.KOTLIN_1_9)
here, I'm getting an error:
Inconsistent settings for Kotlin source sets: 'jvmMain' depends on 'jvmCommonMain'
'jvmMain': language version is KOTLIN_1_9
'jvmCommonMain': language version is KOTLIN_2_0
The language version of the dependent source set must be greater than or equal to that of its dependency.
tasks.withType(KotlinCompilationTask::class.java).configureEach { | ||
compilerOptions { | ||
apiVersion.set(KotlinVersion.KOTLIN_1_9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a parametter of apolloLibrary()
and apolloTest()
?
build-logic/src/main/kotlin/api.kt
Outdated
class KotlinCompilerOptions( | ||
val apiVersion: KotlinVersion = KotlinVersion.KOTLIN_2_0, | ||
val languageVersion: KotlinVersion = KotlinVersion.KOTLIN_2_0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: is there any occurrence where we're not setting the same value for both parameters? I would probably have gone with a single parameter but 2 work too 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you're totally right :) Changed it to a single version
parameter
* Bump apiVersion and languageVersion to KOTLIN_2_0 * Update API dump * Use apiVersion KOTLIN_1_9 in apollo-debug-server du to KSP 1 * Don't expose BaseVariant in AndroidProject's API * Move compiler options to apolloLibrary/apolloTest * Keep a single parameter for both versions
Also, I tried to enable KSP 2 but it crashes due to google/ksp#1823 (which needs a fix that will be in Kotlin 2.1).