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

Migrate from kotlinOptions to compilerOptions #2746

Merged
merged 11 commits into from
Aug 23, 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
10 changes: 4 additions & 6 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.gradle.kotlin.dsl.support.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand Down Expand Up @@ -40,15 +41,12 @@ tasks.assemble {
dependsOn(tasks.jmhClasses)
}

tasks.withType<KotlinCompile>().configureEach {
kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}

kotlinOptions {
if (overriddenLanguageVersion != null) {
languageVersion = overriddenLanguageVersion
freeCompilerArgs += "-Xsuppress-version-warnings"
languageVersion = KotlinVersion.fromVersion(overriddenLanguageVersion!!)
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions buildSrc/src/main/kotlin/Java9Modularity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.gradle.targets.jvm.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.tooling.core.*
import java.io.*
import kotlin.reflect.*
Expand Down Expand Up @@ -113,6 +114,7 @@ object Java9Modularity {
sourceFile: File
): TaskProvider<out KotlinJvmCompile> {
apply<KotlinApiPlugin>()
@Suppress("DEPRECATION")
val verifyModuleTaskName = "verify${compileTask.name.removePrefix("compile").capitalize()}Module"
// work-around for https://youtrack.jetbrains.com/issue/KT-60542
val kotlinApiPlugin = plugins.getPlugin(KotlinApiPlugin::class)
Expand All @@ -139,7 +141,7 @@ object Java9Modularity {
freeCompilerArgs.addAll(
listOf("-Xjdk-release=9", "-Xsuppress-version-warnings", "-Xexpect-actual-classes")
)
optIn.addAll(compileTask.kotlinOptions.options.optIn)
optIn.addAll(compileTask.compilerOptions.optIn)
}
// work-around for https://youtrack.jetbrains.com/issue/KT-60583
inputs.files(
Expand All @@ -160,7 +162,7 @@ object Java9Modularity {
.declaredMemberProperties
.find { it.name == "ownModuleName" }
?.get(this) as? Property<String>
ownModuleNameProp?.set(compileTask.kotlinOptions.moduleName)
ownModuleNameProp?.set(compileTask.compilerOptions.moduleName)
}

val taskKotlinLanguageVersion = compilerOptions.languageVersion.orElse(KotlinVersion.DEFAULT)
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ fun Project.propertyIsTrue(propertyName: String): Boolean {
return (findProperty(propertyName) as? String?).equals("true", true)
}

val Project.jdkToolchainVersion: Int get() = findProperty("jdk_toolchain_version").toString().toInt()

val Project.overriddenLanguageVersion : String?
get() = findProperty("kotlin_language_version") as String?

Expand Down
52 changes: 24 additions & 28 deletions buildSrc/src/main/kotlin/source-sets-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@
@file:OptIn(ExperimentalWasmDsl::class)

import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.testing.*

plugins {
kotlin("multiplatform")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}

tasks.withType<JavaCompile>().configureEach {
options.release = 8
}
Expand All @@ -30,13 +27,13 @@ kotlin {

jvm {
withJava()
compilations.configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xjdk-release=1.8"
}
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
freeCompilerArgs.add("-Xjdk-release=1.8")
}
}
jvmToolchain(jdkToolchainVersion)
Copy link
Member

Choose a reason for hiding this comment

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

It wasn't here before, why is it needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In master (2.0.20), KGP requires toolchain and and jvmTarget to be consistent. Otherwise, things like org.gradle.api.InvalidUserCodeException: Inconsistent JVM-target compatibility detected for tasks 'compileTestJava' (1.8) and 'compileTestKotlin' (11). pop up

Copy link
Member

Choose a reason for hiding this comment

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

Hm, given that we have both options.release = 8 in JavaCompile and freeCompilerArgs.add("-Xjdk-release=1.8") in KotlinCompile, do we actually need toolchains?

Copy link
Member

Choose a reason for hiding this comment

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

Since you've added jdkToolchainVersion as a property, this block on line 21:

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}

probably should use it as well instead of JavaLanguageVersion.of(11)


js {
nodejs {
Expand All @@ -46,11 +43,11 @@ kotlin {
}
}
}
compilations.matching { it.name == "main" || it.name == "test" }.configureEach {
kotlinOptions {
sourceMap = true
moduleKind = "umd"
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
sourceMap = true
moduleKind = JsModuleKind.MODULE_UMD
}
}

Expand Down Expand Up @@ -154,19 +151,18 @@ kotlin {
optIn("kotlinx.serialization.ExperimentalSerializationApi")
}
}
}

targets.all {
compilations.all {
kotlinOptions {
if (overriddenLanguageVersion != null) {
languageVersion = overriddenLanguageVersion
freeCompilerArgs += "-Xsuppress-version-warnings"
}
freeCompilerArgs += "-Xexpect-actual-classes"
}
}
compilations["main"].kotlinOptions {
tasks.withType(KotlinCompilationTask::class).configureEach {
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
compilerOptions {
val isMainTaskName = name.startsWith("compileKotlin")
if (isMainTaskName) {
allWarningsAsErrors = true
}
if (overriddenLanguageVersion != null) {
languageVersion = KotlinVersion.fromVersion(overriddenLanguageVersion!!)
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ tasks.withType<Jar>().named(kotlin.jvm().artifactsTaskName) {
configureJava9ModuleInfo()

tasks.withType<KotlinJsIrLink>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xwasm-enable-array-range-checks"
compilerOptions.freeCompilerArgs.add("-Xwasm-enable-array-range-checks")
}
25 changes: 11 additions & 14 deletions formats/hocon/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@ plugins {
alias(libs.plugins.serialization)
}

tasks.compileKotlin {
compilerOptions {
allWarningsAsErrors = true
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlin {
jvmToolchain(jdkToolchainVersion)
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
if (overriddenLanguageVersion != null) {
languageVersion = KotlinVersion.fromVersion(overriddenLanguageVersion!!)
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
freeCompilerArgs.add("-Xjdk-release=1.8")
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
if (overriddenLanguageVersion != null) {
languageVersion = overriddenLanguageVersion
freeCompilerArgs += "-Xsuppress-version-warnings"
}
// Only main
tasks.compileKotlin {
compilerOptions {
allWarningsAsErrors = true
}
}

Expand All @@ -38,7 +36,6 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}


dependencies {
api(project(":kotlinx-serialization-core"))
api("org.jetbrains.kotlin:kotlin-stdlib")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

group=org.jetbrains.kotlinx
version=1.7.2-SNAPSHOT

jdk_toolchain_version=11
# This version takes precedence if 'bootstrap' property passed to project
kotlin.version.snapshot=2.0.255-SNAPSHOT
# Also set KONAN_LOCAL_DIST environment variable in bootstrap mode to auto-assign konan.home
Expand Down
9 changes: 4 additions & 5 deletions guide/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/*
Expand All @@ -11,13 +12,11 @@ plugins {

kotlin {
jvmToolchain(8)
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
compilerOptions {
if (overriddenLanguageVersion != null) {
languageVersion = overriddenLanguageVersion
freeCompilerArgs += "-Xsuppress-version-warnings"
languageVersion = KotlinVersion.fromVersion(overriddenLanguageVersion!!)
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
}
}
Expand Down