forked from Kotlin/kotlinx.coroutines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
361 lines (306 loc) · 13.7 KB
/
build.gradle
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import static Projects.*
apply plugin: 'jdk-convention'
buildscript {
/*
* These property group is used to build kotlinx.coroutines 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 is overwritten by TeamCity environment (AFU is built with snapshot and published to mavenLocal
* as previous step or the snapshot build).
* 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.
*/
def prop = rootProject.properties['build_snapshot_train']
ext.build_snapshot_train = prop != null && prop != ""
if (build_snapshot_train) {
ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
if (kotlin_version == null) {
throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
}
}
ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null
// Determine if any project dependency is using a snapshot version
ext.using_snapshot_version = build_snapshot_train
rootProject.properties.each { key, value ->
if (key.endsWith("_version") && value instanceof String && value.endsWith("-SNAPSHOT")) {
println("NOTE: USING SNAPSHOT VERSION: $key=$value")
ext.using_snapshot_version = true
}
}
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
mavenLocal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
classpath "com.github.node-gradle:gradle-node-plugin:$gradle_node_version"
classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
classpath "ru.vyarus:gradle-animalsniffer-plugin:1.5.4" // Android API check
classpath "org.jetbrains.kotlinx:kover:$kover_version"
// JMH plugins
classpath "gradle.plugin.com.github.johnrengelman:shadow:7.1.2"
}
CacheRedirector.configureBuildScript(buildscript, rootProject)
}
// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
if (!Idea.active) {
ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
}
// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
def configureKotlinJvmPlatform(configuration) {
configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
}
allprojects {
// the only place where HostManager could be instantiated
project.ext.hostManager = new HostManager()
def deployVersion = properties['DeployVersion']
if (deployVersion != null) version = deployVersion
if (build_snapshot_train) {
ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
println "Using Kotlin $kotlin_version for project $it"
def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
if (!skipSnapshotChecks && version != atomicfu_version) {
throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
}
kotlin_version = rootProject.properties['kotlin_snapshot_version']
}
ext.unpublished = unpublished
// This project property is set during nightly stress test
def stressTest = project.properties['stressTest']
// Copy it to all test tasks
tasks.withType(Test) {
systemProperty 'stressTest', stressTest
}
}
apply plugin: "binary-compatibility-validator"
apply plugin: "base"
apply plugin: "kover-conventions"
apiValidation {
ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
if (build_snapshot_train) {
ignoredProjects.remove("example-frontend-js")
ignoredProjects.add(coreModule)
}
ignoredPackages += "kotlinx.coroutines.internal"
}
// Configure repositories
allprojects {
repositories {
/*
* google should be first in the repository list because some of the play services
* transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
*/
google()
mavenCentral()
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
}
}
// needs to be before evaluationDependsOn due to weird Gradle ordering
apply plugin: "animalsniffer-conventions"
// Add dependency to core source sets. Core is configured in kx-core/build.gradle
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
evaluationDependsOn(":$coreModule")
if (isMultiplatform(it)) {
apply plugin: "kotlin-multiplatform"
apply from: rootProject.file("gradle/compile-jvm-multiplatform.gradle")
apply from: rootProject.file("gradle/compile-common.gradle")
if (rootProject.ext["native_targets_enabled"] as Boolean) {
apply from: rootProject.file("gradle/compile-native-multiplatform.gradle")
}
apply from: rootProject.file("gradle/compile-js-multiplatform.gradle")
apply from: rootProject.file("gradle/publish-npm-js.gradle")
kotlin.sourceSets.commonMain.dependencies {
api project(":$coreModule")
}
kotlin.sourceSets.jvmTest.dependencies {
implementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
}
} else {
def platform = PlatformKt.platformOf(it)
apply plugin: "kotlin-${platform}-conventions"
dependencies {
api project(":$coreModule")
// the only way IDEA can resolve test classes
testImplementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
}
}
}
apply plugin: "bom-conventions"
// Configure subprojects with Kotlin sources
configure(subprojects.findAll { !sourceless.contains(it.name) }) {
// Use atomicfu plugin, it also adds all the necessary dependencies
apply plugin: 'kotlinx-atomicfu'
// Configure options for all Kotlin compilation tasks
tasks.withType(AbstractKotlinCompile).all {
kotlinOptions.freeCompilerArgs += OptInPreset.optInAnnotations.collect { "-Xopt-in=" + it }
kotlinOptions.freeCompilerArgs += "-progressive"
// Disable KT-36770 for RxJava2 integration
kotlinOptions.freeCompilerArgs += "-XXLanguage:-ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated"
// Remove null assertions to get smaller bytecode on Android
kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
}
}
if (build_snapshot_train) {
println "Hacking test tasks, removing stress and flaky tests"
allprojects {
tasks.withType(Test).all {
exclude '**/*LinearizabilityTest*'
exclude '**/*LFTest*'
exclude '**/*StressTest*'
exclude '**/*scheduling*'
exclude '**/*Timeout*'
exclude '**/*definitely/not/kotlinx*'
// Disable because of KT-11567 in 1.4
exclude '**/*CasesPublicAPITest*'
// Kotlin
exclude '**/*PrecompiledDebugProbesTest*'
}
}
println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
configure(subprojects.findAll { it.name == coreModule }) {
configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
def manifest = zipTree(it).matching {
include 'META-INF/MANIFEST.MF'
}.getFiles().first()
manifest.readLines().each {
println it
}
}
}
}
}
// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
configure(subprojects.findAll {
!sourceless.contains(it.name) && !isMultiplatform(it) &&
it.name != "benchmarks" &&
it.name != "example-frontend-js"
}) {
// Pure JS and pure MPP doesn't have this notion and are configured separately
// TODO detect it via platformOf and migrate benchmarks to the same scheme
sourceSets {
main.kotlin.srcDirs = ['src']
test.kotlin.srcDirs = ['test']
main.resources.srcDirs = ['resources']
test.resources.srcDirs = ['test-resources']
}
}
def core_docs_url = "https://kotlinlang.org/api/kotlinx.coroutines/$coreModule/"
def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/htmlPartial/package-list"
apply plugin: "org.jetbrains.dokka"
configure(subprojects.findAll { !unpublished.contains(it.name) && it.name != coreModule }) {
if (it.name != 'kotlinx-coroutines-bom') {
apply from: rootProject.file('gradle/dokka.gradle.kts')
}
apply from: rootProject.file('gradle/publish.gradle')
}
configure(subprojects.findAll { !unpublished.contains(it.name) }) {
if (it.name != "kotlinx-coroutines-bom") {
if (it.name != coreModule) {
tasks.withType(DokkaTaskPartial.class) {
dokkaSourceSets.configureEach {
externalDocumentationLink {
url.set(new URL(core_docs_url))
packageListUrl.set(new File(core_docs_file).toURI().toURL())
}
}
}
}
}
def thisProject = it
if (thisProject.name in sourceless) {
return
}
def versionFileTask = thisProject.tasks.register("versionFileTask") {
def name = thisProject.name.replace("-", "_")
def versionFile = thisProject.layout.buildDirectory.file("${name}.version")
it.outputs.file(versionFile)
it.doLast {
versionFile.get().asFile.text = version.toString()
}
}
List<String> jarTasks
if (isMultiplatform(it)) {
jarTasks = ["jvmJar", "metadataJar"]
} else if (it.name == "kotlinx-coroutines-debug") {
// We shadow debug module instead of just packaging it
jarTasks = ["shadowJar"]
} else {
jarTasks = ["jar"]
}
for (name in jarTasks) {
thisProject.tasks.named(name, Jar) {
it.dependsOn versionFileTask
it.from(versionFileTask) {
into("META-INF")
}
}
}
}
// Report Kotlin compiler version when building project
println("Using Kotlin compiler version: $KotlinCompilerVersion.VERSION")
// --------------- Cache redirector ---------------
allprojects {
CacheRedirector.configure(project)
}
// --------------- Configure sub-projects that are published ---------------
def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
task deploy(dependsOn: publishTasks)
clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
// --------------- Knit configuration ---------------
apply plugin: 'kotlinx-knit'
knit {
siteRoot = "https://kotlinlang.org/api/kotlinx.coroutines"
moduleRoots = [".", "integration", "reactive", "ui"]
moduleDocs = "build/dokka/htmlPartial"
dokkaMultiModuleRoot = "build/dokka/htmlMultiModule/"
}
knitPrepare.dependsOn getTasksByName("dokkaHtmlMultiModule", true)
dependencies {
dokkaHtmlMultiModulePlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")
}
// Opt-in for build scan in order to troubleshoot Gradle on TC
if (hasProperty('buildScan')) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
}
/*
* kotlinx-coroutines-core dependency leaks into test runtime classpath via kotlin-compiler-embeddable
* and conflicts with our own test/runtime incompatibilities (e.g. when class is moved from a main to test),
* so we do substitution here
*/
allprojects { subProject ->
subProject
.configurations
.matching {
// Excluding substituted project itself because of circular dependencies, but still do it
// for "*Test*" configurations
subProject.name != coreModule || it.name.contains("Test")
}
.configureEach { conf ->
conf.resolutionStrategy.dependencySubstitution {
substitute(module("org.jetbrains.kotlinx:$coreModule"))
.using(project(":$coreModule"))
.because("Because Kotlin compiler embeddable leaks coroutines into the runtime classpath, " +
"triggering all sort of incompatible class changes errors")
}
}
}
tasks.named("dokkaHtmlMultiModule") {
pluginsMapConfiguration.set(["org.jetbrains.dokka.base.DokkaBase": """{ "templatesDir": "${projectDir.toString().replace('\\', '/')}/dokka-templates" }"""])
}