Skip to content

Commit 06795ab

Browse files
committed
Rework infrastructure for builds as a Kotlin user project
1 parent 27d39ba commit 06795ab

File tree

5 files changed

+99
-85
lines changed

5 files changed

+99
-85
lines changed

benchmarks/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
2+
13
/*
24
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
35
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
@@ -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: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
2+
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
3+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
4+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
5+
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
6+
17
plugins {
28
id("kotlinx.team.infra") version "0.4.0-dev-85"
39
kotlin("multiplatform") apply false
@@ -22,21 +28,16 @@ val modularJavaToolchainVersion by ext(project.property("java.modularToolchainVe
2228

2329
allprojects {
2430
repositories {
25-
addTrainRepositories(project)
2631
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=disable") }
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") }
32+
33+
// !! infrastructure for builds as a Kotlin user project
34+
val optionalKotlinArtifactsRepo = providers.gradleProperty("kotlin_repo_url").orNull
35+
if (optionalKotlinArtifactsRepo != null) {
36+
maven(url = optionalKotlinArtifactsRepo)
37+
logger.info(
38+
"[ktDT-as-KUP] Registered '$optionalKotlinArtifactsRepo' as a dependency Maven repository for '${path}'"
39+
)
40+
}
4041
}
4142
}
4243

@@ -61,3 +62,43 @@ dependencies {
6162
kover(project(":kotlinx-datetime"))
6263
kover(project(":kotlinx-datetime-serialization"))
6364
}
65+
66+
// !! infrastructure for builds as a Kotlin user project
67+
subprojects {
68+
tasks.withType<KotlinCompilationTask<*>>().configureEach {
69+
compilerOptions {
70+
// output kotlin.git-searchable names of reported diagnostics
71+
freeCompilerArgs.add("-Xrender-internal-diagnostic-names")
72+
73+
with(providers) {
74+
gradleProperty("kotlin_language_version").orNull?.let { optionalOverridingKotlinLV ->
75+
languageVersion.set(KotlinVersion.fromVersion(optionalOverridingKotlinLV))
76+
logger.info(
77+
"[ktDT-as-KUP] Overrode the Kotlin language version with $optionalOverridingKotlinLV for '$path'"
78+
)
79+
}
80+
gradleProperty("kotlin_api_version").orNull?.let { optionalOverridingKotlinAPIV ->
81+
apiVersion.set(KotlinVersion.fromVersion(optionalOverridingKotlinAPIV))
82+
logger.info(
83+
"[ktDT-as-KUP] Overrode the Kotlin API version with $optionalOverridingKotlinAPIV for '$path'"
84+
)
85+
}
86+
}
87+
}
88+
}
89+
tasks.withType<KotlinJvmCompile>().configureEach {
90+
compilerOptions {
91+
freeCompilerArgs.add("-Xjvm-default=disable")
92+
}
93+
}
94+
tasks.withType<KotlinNativeCompile>().configureEach {
95+
compilerOptions {
96+
freeCompilerArgs.add("-Xpartial-linkage-loglevel=error")
97+
}
98+
}
99+
tasks.withType<Kotlin2JsCompile>().configureEach {
100+
compilerOptions {
101+
freeCompilerArgs.add("-Xpartial-linkage-loglevel=error")
102+
}
103+
}
104+
}

buildSrc/build.gradle.kts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,38 @@ 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+
val optionalKotlinArtifactsRepo = providers.gradleProperty("kotlin_repo_url").orNull
17+
if (optionalKotlinArtifactsRepo != null) {
18+
maven(url = optionalKotlinArtifactsRepo)
19+
logger.info(
20+
"[ktDT-as-KUP] Registered '$optionalKotlinArtifactsRepo' as a dependency Maven repository for buildSrc"
21+
)
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")
25+
// !! infrastructure for builds as a Kotlin user project
26+
val Project.kotlinVersion: String by lazy {
27+
val optionalOverridingKotlinVersion = providers.gradleProperty("kotlin_version").orNull
28+
if (optionalOverridingKotlinVersion != null) {
29+
logger.info(
30+
"[ktDT-as-KUP] Overrode the Kotlin distribution version with $optionalOverridingKotlinVersion"
31+
)
32+
optionalOverridingKotlinVersion
33+
} else {
34+
// we don't have access to the properties defined in `gradle.properties` of the encompassing project,
35+
// so we have to get them manually
36+
val properties = Properties().apply {
37+
file("../gradle.properties").inputStream().use { load(it) }
38+
}
39+
properties.getProperty("defaultKotlinVersion")
40+
}
3041
}
3142

32-
repositories {
33-
mavenCentral()
34-
gradlePluginPortal()
35-
addTrainRepositories(project)
36-
}
37-
3843
dependencies {
3944
fun gradlePlugin(id: String, version: String): String = "$id:$id.gradle.plugin:$version"
4045
implementation(gradlePlugin("org.jetbrains.kotlin.multiplatform", kotlinVersion))

buildSrc/src/main/kotlin/CommunityProjectsBuild.kt

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

settings.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ pluginManagement {
33
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/maven")
44
mavenCentral()
55
gradlePluginPortal()
6+
7+
// !! infrastructure for builds as a Kotlin user project
8+
val optionalKotlinArtifactsRepo = providers.gradleProperty("kotlin_repo_url").orNull
9+
if (optionalKotlinArtifactsRepo != null) {
10+
maven(url = optionalKotlinArtifactsRepo)
11+
logger.info(
12+
"[ktDT-as-KUP] Registered '$optionalKotlinArtifactsRepo' as a plugin Maven repository"
13+
)
14+
}
615
}
716
val dokkaVersion: String by settings
817
val benchmarksVersion: String by settings

0 commit comments

Comments
 (0)