Skip to content

Commit 7114d4a

Browse files
Backport kxDT-as-KUP infrastructure and migration changes (#560)
* Update Gradle to 8.5 - JDK 21 support is required for builds as a Kotlin user project * Rework infrastructure for builds as a Kotlin user project * Perform a minor Kotlin-related cleanup - the deprecated `kotlin.js.compiler` Gradle property is removed from `gradle.properties` - the deprecated `kotlin.native.ignoreIncorrectDependencies` Gradle property is removed from `gradle.properties` - `:kotlinx-datetime:compileCommonJsMainKotlinMetadata` task is enabled back to preserve compilation correctness (see KT-66382 for more details) * [migration to Kotlin 1.9.24] Update build scripts w.r.t. KT-65864 * [migration to Kotlin 2.2.0] Update build scripts w.r.t. KT-54110 * [migration to Kotlin 2.2.0] Update Kotlin code w.r.t. KT-74897 * [migration to Kotlin APIV 2.2] Update Kotlin code w.r.t. KT-76394 * [migration to Kotlin 2.2.20] Update Kotlin code w.r.t. KT-77986 --------- Co-authored-by: Nikolay Lunyak <nikolay.lunyak@jetbrains.com>
1 parent 9cb38da commit 7114d4a

File tree

14 files changed

+326
-143
lines changed

14 files changed

+326
-143
lines changed

benchmarks/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

6+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
7+
68
plugins {
79
id("kotlin")
810
id("me.champeau.jmh")
@@ -32,3 +34,10 @@ tasks.named<Jar>("jmhJar") {
3234
repositories {
3335
mavenCentral()
3436
}
37+
38+
// !! infrastructure for builds as a Kotlin user project
39+
tasks.named("assemble") {
40+
// compile all Kotlin code from the module during full-repository builds
41+
// so that it's covered during builds as a Kotlin user project
42+
dependsOn(tasks.withType<KotlinCompilationTask<*>>())
43+
}

build.gradle.kts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
3+
14
plugins {
25
id("kotlinx.team.infra") version "0.4.0-dev-85"
36
kotlin("multiplatform") apply false
@@ -22,28 +25,25 @@ val modularJavaToolchainVersion by ext(project.property("java.modularToolchainVe
2225

2326
allprojects {
2427
repositories {
25-
addTrainRepositories(project)
2628
mavenCentral()
27-
}
28-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
29-
// outputs the compiler version to logs so we can check whether the train configuration applied
30-
kotlinOptions.freeCompilerArgs += "-version"
31-
}
32-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile>().configureEach {
33-
compilerOptions { freeCompilerArgs.add("-Xjvm-default=all-compatibility") }
34-
}
35-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile>().configureEach {
36-
compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") }
37-
}
38-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configureEach {
39-
compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") }
29+
kupInfra {
30+
kupArtifactsRepo(context = project)
31+
}
4032
}
4133
}
4234

43-
// Disable NPM to NodeJS nightly compatibility check.
44-
// Drop this when NodeJs version that supports latest Wasm become stable
45-
tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask>().configureEach {
46-
args.add("--ignore-engines")
35+
subprojects {
36+
// drop this after migration to 2.2.0
37+
tasks.withType<KotlinJvmCompile>().configureEach {
38+
compilerOptions {
39+
freeCompilerArgs.add("-Xjvm-default=all-compatibility")
40+
}
41+
}
42+
kupInfra {
43+
tasks.withType<KotlinCompilationTask<*>>().configureEach {
44+
kupConfiguration()
45+
}
46+
}
4747
}
4848

4949
kover {

buildSrc/build.gradle.kts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,40 @@ plugins {
88
`kotlin-dsl`
99
}
1010

11-
val props = Properties().apply {
12-
file("../gradle.properties").inputStream().use { load(it) }
13-
}
11+
repositories {
12+
mavenCentral()
13+
gradlePluginPortal()
1414

15-
// copy-pasted from `CommunityProjectsBuild`, see the explanation there
16-
fun RepositoryHandler.addTrainRepositories(project: Project) {
17-
if (project.rootProject.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) {
18-
mavenLocal()
15+
// !! infrastructure for builds as a Kotlin user project
16+
// this is an inlined version of `KotlinUserProjectUtilities.kupArtifactsRepo`
17+
// (because `buildSrc/.../KotlinUserProjectInfra.kt` is not available here)
18+
val kupArtifactsRepoURL = providers.gradleProperty("kotlin_repo_url").orNull
19+
if (kupArtifactsRepoURL != null) {
20+
maven(kupArtifactsRepoURL)
21+
logger.lifecycle("[KUP infra] Added '$kupArtifactsRepoURL' as a Maven repo to ':buildSrc'")
1922
}
20-
(project.rootProject.properties["kotlin_repo_url"] as? String)?.let(::maven)
2123
}
2224

23-
// copy-pasted from `CommunityProjectsBuild`, but uses `props` to obtain the non-snapshot version, because
24-
// we don't have access to the properties defined in `gradle.properties` of the encompassing project
25-
val Project.kotlinVersion: String
26-
get() = if (rootProject.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) {
27-
rootProject.properties["kotlin_snapshot_version"] as? String ?: error("kotlin_snapshot_version must be specified")
28-
} else {
29-
props.getProperty("defaultKotlinVersion")
30-
}
31-
32-
repositories {
33-
mavenCentral()
34-
gradlePluginPortal()
35-
addTrainRepositories(project)
25+
// !! infrastructure for builds as a Kotlin user project
26+
/**
27+
* the value provided via the `kotlin_version` Gradle property if any
28+
* (otherwise, `defaultKotlinVersion` defined in `gradle.properties` of the root project is used instead);
29+
* note that there is no direct `buildSrc/.../KotlinUserProjectInfra.kt` analogue for this utility
30+
* because `kotlin_version` is commonly used where `buildSrc/.../KotlinUserProjectInfra.kt` is not available
31+
* (`settings.gradle.kts`, `buildSrc`, etc.)
32+
*/
33+
val Project.kotlinVersion: String by lazy {
34+
val kotlinVersion: String = providers.gradleProperty("kotlin_version").orNull
35+
?: run {
36+
// we don't have access to the properties defined in `gradle.properties` of the root project,
37+
// so we have to get them manually
38+
val properties = Properties().apply {
39+
file("../gradle.properties").inputStream().use { load(it) }
40+
}
41+
properties.getProperty("defaultKotlinVersion")
42+
}
43+
logger.lifecycle("[KUP infra] Set Kotlin distribution version to '$kotlinVersion'")
44+
kotlinVersion
3645
}
3746

3847
dependencies {

buildSrc/src/main/kotlin/CommunityProjectsBuild.kt

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)