diff --git a/build.gradle b/build.gradle index 26b598ff5d..9dd9e74517 100644 --- a/build.gradle +++ b/build.gradle @@ -2,20 +2,14 @@ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ + import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.dokka.gradle.DokkaTaskPartial -apply plugin: 'jdk-convention' +import static Projects.* -def coreModule = "kotlinx-coroutines-core" -def testModule = "kotlinx-coroutines-test" -def multiplatform = [coreModule, testModule] -// Not applicable for Kotlin plugin -def sourceless = ['kotlinx.coroutines', 'kotlinx-coroutines-bom', 'integration-testing'] -def internal = ['kotlinx.coroutines', 'benchmarks', 'integration-testing'] -// Not published -def unpublished = internal + ['example-frontend-js', 'android-unit-tests'] +apply plugin: 'jdk-convention' buildscript { /* @@ -160,6 +154,8 @@ configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != core } } +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 diff --git a/buildSrc/src/main/kotlin/Projects.kt b/buildSrc/src/main/kotlin/Projects.kt index dd284b6132..d5494e16cd 100644 --- a/buildSrc/src/main/kotlin/Projects.kt +++ b/buildSrc/src/main/kotlin/Projects.kt @@ -1,8 +1,20 @@ /* * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ - +@file:JvmName("Projects") import org.gradle.api.Project fun Project.version(target: String): String = property("${target}_version") as String + +val coreModule = "kotlinx-coroutines-core" +val testModule = "kotlinx-coroutines-test" + +val multiplatform = setOf(coreModule, testModule) +// Not applicable for Kotlin plugin +val sourceless = setOf("kotlinx.coroutines", "kotlinx-coroutines-bom", "integration-testing") +val internal = setOf("kotlinx.coroutines", "benchmarks", "integration-testing") +// Not published +val unpublished = internal + setOf("example-frontend-js", "android-unit-tests") + +val Project.isMultiplatform: Boolean get() = name in multiplatform diff --git a/buildSrc/src/main/kotlin/bom-conventions.gradle.kts b/buildSrc/src/main/kotlin/bom-conventions.gradle.kts new file mode 100644 index 0000000000..45f30edff1 --- /dev/null +++ b/buildSrc/src/main/kotlin/bom-conventions.gradle.kts @@ -0,0 +1,19 @@ +/* + * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.dsl.* + + +configure(subprojects.filter { it.name !in unpublished }) { + if (name == "kotlinx-coroutines-bom" || name == "kotlinx.coroutines") return@configure + if (isMultiplatform) { + kotlinExtension.sourceSets.getByName("jvmMain").dependencies { + api(project.dependencies.platform(project(":kotlinx-coroutines-bom"))) + } + } else { + dependencies { + "api"(platform(project(":kotlinx-coroutines-bom"))) + } + } +}