forked from ktorio/ktor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
218 lines (177 loc) · 6.48 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
import org.jetbrains.dokka.gradle.*
import org.jetbrains.kotlin.buildtools.api.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.targets.js.*
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.konan.target.*
buildscript {
/*
* These property group is used to build ktor against Kotlin compiler snapshot.
* How does it work:
* When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version,
* atomicfu_version, coroutines_version, serialization_version and kotlinx_io_version are overwritten by TeamCity environment.
* Additionally, mavenLocal and Sonatype snapshots are added to repository list and stress tests are disabled.
* DO NOT change the name of these properties without adapting kotlinx.train build chain.
*/
extra["build_snapshot_train"] = rootProject.properties["build_snapshot_train"]
val build_snapshot_train: String? by extra
if (build_snapshot_train.toBoolean()) {
extra["kotlin_version"] = rootProject.properties["kotlin_snapshot_version"]
val kotlin_version: String? by extra
if (kotlin_version == null) {
throw IllegalArgumentException(
"'kotlin_snapshot_version' should be defined when building with snapshot compiler",
)
}
repositories {
maven(url = "https://oss.sonatype.org/content/repositories/snapshots") {
mavenContent { snapshotsOnly() }
}
mavenLocal()
}
configurations.classpath {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlin") {
useVersion(kotlin_version!!)
}
}
}
}
repositories {
mavenCentral()
google()
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
mavenLocal()
}
}
val releaseVersion: String? by extra
val eapVersion: String? by extra
val version = (project.version as String).let { if (it.endsWith("-SNAPSHOT")) it.dropLast("-SNAPSHOT".length) else it }
extra["configuredVersion"] = when {
releaseVersion != null -> releaseVersion
eapVersion != null -> "$version-eap-$eapVersion"
else -> project.version
}
println("The build version is ${extra["configuredVersion"]}")
extra["globalM2"] = "${project.file("build")}/m2"
extra["publishLocal"] = project.hasProperty("publishLocal")
val configuredVersion: String by extra
apply(from = "gradle/verifier.gradle")
extra["skipPublish"] = mutableListOf(
"ktor-server-test-base",
"ktor-junit"
)
extra["nonDefaultProjectStructure"] = mutableListOf(
"ktor-bom",
"ktor-java-modules-test",
)
val disabledExplicitApiModeProjects = listOf(
"ktor-client-tests",
"ktor-server-test-base",
"ktor-server-test-suites",
"ktor-server-tests",
"ktor-client-content-negotiation-tests",
"ktor-junit"
)
apply(from = "gradle/compatibility.gradle")
plugins {
id("org.jetbrains.dokka") version "1.9.20" apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.16.2"
id("org.jetbrains.kotlinx.atomicfu") version "0.25.0" apply false
id("com.osacky.doctor") version "0.10.0"
}
doctor {
enableTestCaching = false
}
allprojects {
group = "io.ktor"
version = configuredVersion
extra["hostManager"] = HostManager()
setupTrainForSubproject()
repositories {
mavenLocal()
mavenCentral()
maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/dev")
}
val nonDefaultProjectStructure: List<String> by rootProject.extra
if (nonDefaultProjectStructure.contains(project.name)) return@allprojects
apply(plugin = "kotlin-multiplatform")
apply(plugin = "org.jetbrains.kotlinx.atomicfu")
configureTargets()
configurations {
maybeCreate("testOutput")
}
kotlin {
if (!disabledExplicitApiModeProjects.contains(project.name)) explicitApi()
setCompilationOptions()
configureSourceSets()
setupJvmToolchain()
}
val skipPublish: List<String> by rootProject.extra
if (!skipPublish.contains(project.name)) {
configurePublication()
}
}
subprojects {
configureCodestyle()
}
println("Using Kotlin compiler version: ${org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION}")
filterSnapshotTests()
fun configureDokka() {
allprojects {
plugins.apply("org.jetbrains.dokka")
val dokkaPlugin by configurations
dependencies {
dokkaPlugin("org.jetbrains.dokka:versioning-plugin:1.9.20")
}
}
val dokkaOutputDir = "../versions"
tasks.withType<DokkaMultiModuleTask> {
val id = "org.jetbrains.dokka.versioning.VersioningPlugin"
val config = """{ "version": "$configuredVersion", "olderVersionsDir":"$dokkaOutputDir" }"""
val mapOf = mapOf(id to config)
outputDirectory.set(file(projectDir.toPath().resolve(dokkaOutputDir).resolve(configuredVersion)))
pluginsMapConfiguration.set(mapOf)
}
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().ignoreScripts = false
}
}
configureDokka()
fun Project.setupJvmToolchain() {
val jdk = when (project.name) {
in jdk11Modules -> 11
else -> 8
}
kotlin {
jvmToolchain(jdk)
}
}
fun KotlinMultiplatformExtension.setCompilationOptions() {
targets.all {
compilations.all {
configureCompilation()
}
}
}
fun KotlinMultiplatformExtension.configureSourceSets() {
sourceSets
.matching { it.name !in listOf("main", "test") }
.all {
val srcDir = if (name.endsWith("Main")) "src" else "test"
val resourcesPrefix = if (name.endsWith("Test")) "test-" else ""
val platform = name.dropLast(4)
kotlin.srcDir("$platform/$srcDir")
resources.srcDir("$platform/${resourcesPrefix}resources")
languageSettings.apply {
progressiveMode = true
}
}
}