From 9c46d868290bacab156eb44714f06d60a08f3d6b Mon Sep 17 00:00:00 2001 From: Alexander Sysoev Date: Thu, 8 Aug 2024 13:45:29 +0200 Subject: [PATCH] Update the project to run tests without the useK2Plugin property (#156) --- compiler-plugin/build.gradle.kts | 2 +- .../src/main/kotlin/util/metaTask.kt | 11 +++-- .../conventions-kotlin-version-jvm.gradle.kts | 13 ------ .../conventions-kotlin-version-kmp.gradle.kts | 15 ------- .../conventions-kotlin-version.gradle.kts | 45 +++++++++++++++++++ .../src/main/kotlin/util/CompilerOptions.kt | 23 ---------- .../main/kotlin/conventions-common.gradle.kts | 1 + .../main/kotlin/conventions-jvm.gradle.kts | 1 - .../main/kotlin/conventions-kmp.gradle.kts | 1 - gradle.properties | 3 -- kotlin-js-store/yarn.lock | 5 +++ 11 files changed, 59 insertions(+), 61 deletions(-) delete mode 100644 gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version-jvm.gradle.kts delete mode 100644 gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version-kmp.gradle.kts create mode 100644 gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version.gradle.kts delete mode 100644 gradle-conventions/latest-only/src/main/kotlin/util/CompilerOptions.kt diff --git a/compiler-plugin/build.gradle.kts b/compiler-plugin/build.gradle.kts index 9b6f9307..34ef158d 100644 --- a/compiler-plugin/build.gradle.kts +++ b/compiler-plugin/build.gradle.kts @@ -12,5 +12,5 @@ allprojects { version = "$kotlinVersion-$rpcVersion" } -configureMetaTasks("cleanTest", "test") +configureMetaTasks("clean", "cleanTest", "test") configureMetaTasks(tasks.matching { it.name.startsWith("publish") }.map { it.name }) diff --git a/gradle-conventions-settings/src/main/kotlin/util/metaTask.kt b/gradle-conventions-settings/src/main/kotlin/util/metaTask.kt index b8a52557..2d9e12e5 100644 --- a/gradle-conventions-settings/src/main/kotlin/util/metaTask.kt +++ b/gradle-conventions-settings/src/main/kotlin/util/metaTask.kt @@ -14,6 +14,12 @@ fun Project.configureMetaTasks(taskNames: List, excludeSubprojects: List val root = this val metaSet = taskNames.toSet() + metaSet.forEach { taskName -> + root.tasks.maybeCreate(taskName).apply { + group = "meta" + } + } + subprojects.forEach { if (it.name in excludeSubprojects) { return@forEach @@ -23,12 +29,9 @@ fun Project.configureMetaTasks(taskNames: List, excludeSubprojects: List val subtask = this if (subtask.name in metaSet) { - val metaTask = root.tasks.findByName(subtask.name) - ?: root.task(subtask.name) + val metaTask = root.tasks.named(subtask.name).get() metaTask.dependsOn(subtask) - - metaTask.group = "meta" } } } diff --git a/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version-jvm.gradle.kts b/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version-jvm.gradle.kts deleted file mode 100644 index c41495ac..00000000 --- a/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version-jvm.gradle.kts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension -import util.optionalProperty -import util.projectLanguageVersion - -val useK2Plugin: Boolean by optionalProperty() - -configure { - compilerOptions(projectLanguageVersion(useK2Plugin)) -} diff --git a/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version-kmp.gradle.kts b/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version-kmp.gradle.kts deleted file mode 100644 index 6a3d3143..00000000 --- a/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version-kmp.gradle.kts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import util.optionalProperty -import util.projectLanguageVersion - -val useK2Plugin: Boolean by optionalProperty() - -@OptIn(ExperimentalKotlinGradlePluginApi::class) -configure { - compilerOptions(projectLanguageVersion(useK2Plugin)) -} diff --git a/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version.gradle.kts b/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version.gradle.kts new file mode 100644 index 00000000..36d1b37e --- /dev/null +++ b/gradle-conventions/latest-only/src/main/kotlin/conventions-kotlin-version.gradle.kts @@ -0,0 +1,45 @@ +/* + * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +import util.lowercase +import util.withKotlinJvmExtension +import util.withKotlinKmpExtension + +/** + * Set the compatibility mode to the lower supported language version. + * + * This should be lined up with the minimal supported compiler plugin version. + * + * We update the language version only for the 'main' sources sets. + * This makes our tests execute against the latest compiler plugin version (for example, with K2 instead of K1). + */ +fun KotlinCommonCompilerOptions.setProjectLanguageVersion() { + languageVersion.set(KotlinVersion.KOTLIN_1_7) + apiVersion.set(KotlinVersion.KOTLIN_1_7) +} + +withKotlinJvmExtension { + target.compilations + .filter { it.isMain } + .forEach { compilation -> + compilation.compileJavaTaskProvider.configure { + compilerOptions.setProjectLanguageVersion() + } + } +} + +withKotlinKmpExtension { + targets.flatMap { it.compilations } + .filter { it.isMain } + .forEach { compilation -> + compilation.compileTaskProvider.configure { + compilerOptions.setProjectLanguageVersion() + } + } +} + +val KotlinCompilation<*>.isMain get() = name.lowercase().contains("main") diff --git a/gradle-conventions/latest-only/src/main/kotlin/util/CompilerOptions.kt b/gradle-conventions/latest-only/src/main/kotlin/util/CompilerOptions.kt deleted file mode 100644 index 5d63bb2f..00000000 --- a/gradle-conventions/latest-only/src/main/kotlin/util/CompilerOptions.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package util - -import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions -import org.jetbrains.kotlin.gradle.dsl.KotlinVersion - -/** - * Set the compatibility mode to the lower supported language version. - * - * This should be lined up with the minimal supported compiler plugin version - */ -fun projectLanguageVersion(useK2Plugin: Boolean): KotlinCommonCompilerOptions.() -> Unit = { - val kotlinVersion = when { - useK2Plugin -> KotlinVersion.KOTLIN_2_0 - else -> KotlinVersion.KOTLIN_1_7 - } - - languageVersion.set(kotlinVersion) - apiVersion.set(kotlinVersion) -} diff --git a/gradle-conventions/src/main/kotlin/conventions-common.gradle.kts b/gradle-conventions/src/main/kotlin/conventions-common.gradle.kts index 4a6ea210..8b847897 100644 --- a/gradle-conventions/src/main/kotlin/conventions-common.gradle.kts +++ b/gradle-conventions/src/main/kotlin/conventions-common.gradle.kts @@ -9,6 +9,7 @@ import util.whenKotlinLatest plugins { id("io.gitlab.arturbosch.detekt") id("conventions-publishing") + id("conventions-kotlin-version") } val globalRootDir: String by extra diff --git a/gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts b/gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts index e1866acb..10c97412 100644 --- a/gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts +++ b/gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts @@ -8,7 +8,6 @@ import util.optInForRPCApi plugins { id("conventions-common") id("org.jetbrains.kotlin.jvm") - id("conventions-kotlin-version-jvm") } java { diff --git a/gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts b/gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts index 596b30ee..ce285873 100644 --- a/gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts +++ b/gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts @@ -10,7 +10,6 @@ import util.optionalProperty plugins { id("conventions-common") id("org.jetbrains.kotlin.multiplatform") - id("conventions-kotlin-version-kmp") } configure { diff --git a/gradle.properties b/gradle.properties index e14ead2f..9eceabf4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,6 +31,3 @@ systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true # uncomment to debug compilation process #kotlin.compiler.execution.strategy=in-process - -# set to true to use K2 RPC compiler plugin to build and run the project (including tests) -kotlinx.rpc.useK2Plugin=false diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index 5edf46cf..b6ed61f7 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -3267,6 +3267,11 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" +typescript@4.7.4: + version "4.7.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" + integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== + typescript@5.4.3: version "5.4.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff"