Skip to content

Commit

Permalink
Migrate from kotlinOptions to compilerOptions (#2746)
Browse files Browse the repository at this point in the history
* WA for KT-68661
* Use Java 11 toolchain

Co-authored-by: Zongle Wang <[email protected]>
  • Loading branch information
qwwdfsad and Goooler authored Aug 23, 2024
1 parent 0b5145c commit 35a9edc
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 57 deletions.
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)

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 {
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

0 comments on commit 35a9edc

Please sign in to comment.