Skip to content

Commit d21a50c

Browse files
committed
Workaround for invalid core dependencies in JVM-only modules
1 parent a85d611 commit d21a50c

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

build.gradle

+23-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.konan.target.HostManager
55

66
apply from: rootProject.file("gradle/experimental.gradle")
77

8+
def rootModule = "kotlinx.coroutines"
89
def coreModule = "kotlinx-coroutines-core"
910
// Not applicable for Kotlin plugin
1011
def sourceless = ['kotlinx.coroutines', 'site']
@@ -82,17 +83,20 @@ allprojects {
8283
maven { url "https://kotlin.bintray.com/kotlinx" }
8384
}
8485

85-
if (projectName == "kotlinx.coroutines" || projectName == coreModule) return
86+
if (projectName == rootModule || projectName == coreModule) return
8687

8788
// Add dependency to core source sets. Core is configured in kx-core/build.gradle
8889
evaluationDependsOn(":$coreModule")
8990
if (sourceless.contains(projectName)) return
9091

9192
def platform = platformOf(it)
9293
apply from: rootProject.file("gradle/compile-${platform}.gradle")
93-
94+
9495
dependencies {
95-
compile project(":$coreModule")
96+
// See comment below for rationale, it will be replaced with "project" dependency
97+
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
98+
compileOnly "org.jetbrains.kotlinx:atomicfu:$atomicFU_version"
99+
96100
// the only way IDEA can resolve test classes
97101
testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
98102
}
@@ -105,6 +109,22 @@ allprojects {
105109
}
106110
}
107111

112+
/*
113+
* Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
114+
* but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
115+
* for JVM-only projects.
116+
*
117+
* We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it
118+
* to have out "project" dependency back.
119+
*/
120+
configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
121+
configurations.all {
122+
resolutionStrategy.dependencySubstitution {
123+
substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
124+
}
125+
}
126+
}
127+
108128
// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
109129
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
110130
sourceSets {

0 commit comments

Comments
 (0)