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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading