Skip to content
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

Merged
merged 6 commits into from
Jun 3, 2024
Merged

Bump languageVersion/apiVersion to Kotlin 2.0 #5931

merged 6 commits into from
Jun 3, 2024

Conversation

BoD
Copy link
Contributor

@BoD BoD commented Jun 3, 2024

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).

@BoD BoD requested review from a team and martinbonnin as code owners June 3, 2024 12:54
Copy link

netlify bot commented Jun 3, 2024

Deploy Preview for apollo-android-docs canceled.

Name Link
🔨 Latest commit 18d7d55
🔍 Latest deploy log https://app.netlify.com/sites/apollo-android-docs/deploys/665dc8cb2e3c150008fa0f50

import org.gradle.api.DomainObjectSet
import org.gradle.api.Project

internal class VariantWrapper(private val _wrapped: BaseVariant) {
Copy link
Contributor Author

@BoD BoD Jun 3, 2024

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 132 to 134
tasks.withType(KotlinCompilationTask::class.java).configureEach {
compilerOptions {
apiVersion.set(KotlinVersion.KOTLIN_1_9)
Copy link
Contributor

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()?

Comment on lines 15 to 17
class KotlinCompilerOptions(
val apiVersion: KotlinVersion = KotlinVersion.KOTLIN_2_0,
val languageVersion: KotlinVersion = KotlinVersion.KOTLIN_2_0,
Copy link
Contributor

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 👍

Copy link
Contributor Author

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

@BoD BoD merged commit e8621ac into main Jun 3, 2024
9 checks passed
@BoD BoD deleted the k2 branch June 3, 2024 16:09
BoD added a commit to BoD/apollo-kotlin that referenced this pull request Jul 1, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants