Skip to content

Commit a20f501

Browse files
authored
Add support for kotlinx-train (#257)
1 parent 8ae1175 commit a20f501

File tree

5 files changed

+98
-5
lines changed

5 files changed

+98
-5
lines changed

build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ val modularJavaToolchainVersion by ext(project.property("java.modularToolchainVe
1919

2020
allprojects {
2121
repositories {
22+
addTrainRepositories(project)
2223
mavenCentral()
2324
}
25+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
26+
// outputs the compiler version to logs so we can check whether the train configuration applied
27+
kotlinOptions.freeCompilerArgs += "-version"
28+
}
2429
}
25-

buildSrc/build.gradle.kts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import java.util.*
6+
7+
plugins {
8+
`kotlin-dsl`
9+
}
10+
11+
val props = Properties().apply {
12+
file("../gradle.properties").inputStream().use { load(it) }
13+
}
14+
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()
19+
}
20+
(project.rootProject.properties["kotlin_repo_url"] as? String)?.let(::maven)
21+
}
22+
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)
36+
}
37+
38+
dependencies {
39+
fun gradlePlugin(id: String, version: String): String = "$id:$id.gradle.plugin:$version"
40+
implementation(gradlePlugin("org.jetbrains.kotlin.multiplatform", kotlinVersion))
41+
implementation(gradlePlugin("org.jetbrains.kotlin.plugin.serialization", kotlinVersion))
42+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
@file:JvmName("CommunityProjectsBuild")
5+
6+
import org.gradle.api.*
7+
import org.gradle.api.artifacts.dsl.*
8+
import org.gradle.api.artifacts.repositories.*
9+
import org.gradle.kotlin.dsl.*
10+
import java.util.logging.*
11+
12+
private val LOGGER: Logger = Logger.getLogger("Kotlin settings logger")
13+
14+
/**
15+
* Functions in this file are responsible for configuring kotlinx-datetime build against a custom dev version
16+
* of Kotlin compiler.
17+
* Such configuration is used in a composite community build of Kotlin in order to check whether not-yet-released changes
18+
* are compatible with our libraries (aka "integration testing that substitues lack of unit testing").
19+
*
20+
* Three parameters are used to configure the build:
21+
* 1. `build_snapshot_train` - if true, the build is run against a snapshot train of Kotlin compiler
22+
* 2. `kotlin_snapshot_version` - if specified, the build uses a custom Kotlin compiler version
23+
* 3. `kotlin_repo_url` - if specified, the build uses a custom Kotlin compiler repository
24+
*
25+
* If `build_snapshot_train` is true, `kotlin_snapshot_version` must be present.
26+
*/
27+
28+
/**
29+
* Adds all the repositories that are needed for the Kotlin aggregate build.
30+
*/
31+
fun RepositoryHandler.addTrainRepositories(project: Project) {
32+
if (project.rootProject.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) {
33+
mavenLocal()
34+
}
35+
// A kotlin-dev space repository with dev versions of Kotlin.
36+
val devRepoUrl = project.rootProject.properties["kotlin_repo_url"] as? String ?: return
37+
LOGGER.info("""Configured Kotlin Compiler repository url: '$devRepoUrl' for project ${project.name}""")
38+
maven(devRepoUrl)
39+
}
40+
41+
/**
42+
* The version of Kotlin compiler to use in the Kotlin aggregate build.
43+
*/
44+
// unused, but may be useful in the future
45+
val Project.kotlinVersion: String
46+
get() = if (rootProject.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) {
47+
rootProject.properties["kotlin_snapshot_version"] as? String ?: error("kotlin_snapshot_version must be specified")
48+
} else {
49+
rootProject.properties["defaultKotlinVersion"] as String
50+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ group=org.jetbrains.kotlinx
55
version=0.4.0
66
versionSuffix=SNAPSHOT
77

8-
kotlinVersion=1.8.10
8+
defaultKotlinVersion=1.8.10
99
dokkaVersion=1.8.10
1010
serializationVersion=1.5.0
1111

settings.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ pluginManagement {
44
mavenCentral()
55
gradlePluginPortal()
66
}
7-
val kotlinVersion: String by settings
87
val dokkaVersion: String by settings
98
plugins {
10-
kotlin("multiplatform") version kotlinVersion
11-
kotlin("plugin.serialization") version kotlinVersion
129
id("org.jetbrains.dokka") version dokkaVersion
1310
}
1411
}

0 commit comments

Comments
 (0)