Skip to content

Commit

Permalink
Bump languageVersion/apiVersion to Kotlin 2.0 (#5931)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BoD authored Jun 3, 2024
1 parent aa41693 commit e8621ac
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 248 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ Some platforms have specific runtime requirements:
At build time, it requires:

* Gradle 8.0+
* Kotlin 1.8+ for JVM projects
* Kotlin 1.9+ for native projects
* Kotlin 1.9+ for JVM projects
* Kotlin 2.0+ for native projects
* Kotlin 2.0+ for JS projects

## Proguard / R8 configuration
Expand Down
11 changes: 5 additions & 6 deletions build-logic/src/main/kotlin/CompilerOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

/**
* @param target the JVM version we want to be compatible with (bytecode + bootstrap classpath)
*/
fun KotlinCommonCompilerOptions.configure(target: Int) {
fun KotlinCommonCompilerOptions.configure(target: Int, kotlinCompilerOptions: KotlinCompilerOptions) {
freeCompilerArgs.add("-Xexpect-actual-classes")

/**
Expand All @@ -34,8 +33,8 @@ fun KotlinCommonCompilerOptions.configure(target: Int) {
freeCompilerArgs.add("-opt-in=com.apollographql.apollo3.annotations.ApolloExperimental")
freeCompilerArgs.add("-opt-in=com.apollographql.apollo3.annotations.ApolloInternal")

apiVersion.set(KotlinVersion.KOTLIN_1_9)
languageVersion.set(KotlinVersion.KOTLIN_1_9)
apiVersion.set(kotlinCompilerOptions.version)
languageVersion.set(kotlinCompilerOptions.version)

when (this) {
is KotlinJvmCompilerOptions -> {
Expand Down Expand Up @@ -94,7 +93,7 @@ val Project.androidExtensionOrNull: BaseExtension?
return (extensions.findByName("android") as? BaseExtension)
}

fun Project.configureJavaAndKotlinCompilers(jvmTarget: Int?) {
fun Project.configureJavaAndKotlinCompilers(jvmTarget: Int?, kotlinCompilerOptions: KotlinCompilerOptions) {
@Suppress("NAME_SHADOWING")
val jvmTarget = jvmTarget?: 8

Expand All @@ -108,7 +107,7 @@ fun Project.configureJavaAndKotlinCompilers(jvmTarget: Int?) {
else -> jvmTarget
}

configure(target)
configure(target, kotlinCompilerOptions)
}
project.tasks.withType(JavaCompile::class.java).configureEach {
// For JVM only modules, this dictates the "org.gradle.jvm.version" Gradle attribute
Expand Down
16 changes: 11 additions & 5 deletions build-logic/src/main/kotlin/api.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@

import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask

class AndroidOptions(
val withCompose: Boolean
val withCompose: Boolean,
)

class KotlinCompilerOptions(
val version: KotlinVersion = KotlinVersion.KOTLIN_2_0,
)

fun Project.apolloLibrary(
Expand All @@ -21,7 +25,8 @@ fun Project.apolloLibrary(
withJvm: Boolean = true,
withWasm: Boolean = true,
androidOptions: AndroidOptions? = null,
publish: Boolean = true
publish: Boolean = true,
kotlinCompilerOptions: KotlinCompilerOptions = KotlinCompilerOptions(),
) {
group = property("GROUP")!!
version = property("VERSION_NAME")!!
Expand All @@ -30,7 +35,7 @@ fun Project.apolloLibrary(
configureAndroid(namespace, androidOptions)
}
commonSetup()
configureJavaAndKotlinCompilers(jvmTarget)
configureJavaAndKotlinCompilers(jvmTarget, kotlinCompilerOptions)

addOptIn(
"com.apollographql.apollo3.annotations.ApolloExperimental",
Expand Down Expand Up @@ -74,9 +79,10 @@ fun Project.apolloTest(
withJvm: Boolean = true,
appleTargets: Set<String> = setOf(hostTarget),
browserTest: Boolean = false,
kotlinCompilerOptions: KotlinCompilerOptions = KotlinCompilerOptions(),
) {
commonSetup()
configureJavaAndKotlinCompilers(null)
configureJavaAndKotlinCompilers(null, kotlinCompilerOptions)
addOptIn(
"com.apollographql.apollo3.annotations.ApolloExperimental",
"com.apollographql.apollo3.annotations.ApolloInternal",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ Some platforms have specific runtime requirements:
At build time, it requires:

* Gradle 8.0+
* Kotlin 1.8+ for JVM projects
* Kotlin 1.9+ for native projects
* Kotlin 1.9+ for JVM projects
* Kotlin 2.0+ for native projects
* Kotlin 2.0+ for JS projects

## Proguard / R8 configuration
Expand Down
Loading

0 comments on commit e8621ac

Please sign in to comment.