Skip to content

Commit ddc2960

Browse files
committed
Configure sourse-sets and compilations for module merger
1 parent a78dd11 commit ddc2960

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

kotlinx-coroutines-core/build.gradle

+50-12
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,41 @@ apply from: rootProject.file('gradle/publish.gradle')
1919
/* ==========================================================================
2020
Configure source sets structure for kotlinx-coroutines-core:
2121
22-
TARGETS SOURCE SETS
23-
------- ----------------------------------------------
22+
TARGETS SOURCE SETS
23+
------- ----------------------------------------------
2424
2525
js -----------------------------------------------------+
2626
|
2727
V
28-
jvm -------------------------------> concurrent ---> common
29-
^
30-
ios \ |
31-
macos | ---> nativeDarwin ---> native --+
28+
jvmCore\ --------> jvm ---------> concurrent -------> common
29+
jdk8 / ^
30+
|
31+
ios \ |
32+
macos | ---> nativeDarwin ---> native ---+
3233
tvos | ^
3334
watchos / |
3435
|
3536
linux \ ---> nativeOther -------+
3637
mingw /
3738
38-
========================================================================== */
39+
40+
Explanation of JVM source sets structure:
41+
42+
The overall structure is just a hack to support the scenario we are interested in:
43+
44+
* We would like to have two source-sets "core" and "jdk8"
45+
* "jdk8" is allowed to use API from Java 8 and from "core"
46+
* "core" is prohibited to use any API from "jdk8"
47+
* It is okay to have test in a single test source-set
48+
* We want to validate source-sets with animal sniffer separately
49+
* And we want to publish a **single** artifact kotlinx-coroutines-core.jar that contains classes from both source-sets
50+
51+
For that, we have following compilations:
52+
* jvmMain compilation: [jvmCoreMain, jdk8Main]
53+
* jvmCore compilation: [commonMain]
54+
* jdk8 compilation: [commonMain, jvmCoreMain]
55+
56+
========================================================================== */
3957

4058
project.ext.sourceSetSuffixes = ["Main", "Test"]
4159

@@ -68,15 +86,12 @@ if (rootProject.ext.native_targets_enabled) {
6886

6987
/* ========================================================================== */
7088

89+
7190
/*
7291
* All platform plugins and configuration magic happens here instead of build.gradle
7392
* because JMV-only projects depend on core, thus core should always be initialized before configuration.
7493
*/
7594
kotlin {
76-
sourceSets.forEach {
77-
SourceSetsKt.configureMultiplatform(it)
78-
}
79-
8095
/*
8196
* Configure two test runs:
8297
* 1) New memory model, Main thread
@@ -104,13 +119,36 @@ kotlin {
104119
}
105120
}
106121

122+
def jvmMain = sourceSets.jvmMain
123+
def jvmCoreMain = sourceSets.create('jvmCoreMain')
124+
def jdk8Main = sourceSets.create('jdk8Main')
125+
jvmCoreMain.dependsOn(jvmMain)
126+
jdk8Main.dependsOn(jvmMain)
127+
128+
sourceSets.forEach {
129+
SourceSetsKt.configureMultiplatform(it)
130+
}
131+
132+
jvm {
133+
def main = compilations.main
134+
main.source(jvmCoreMain)
135+
main.source(jdk8Main)
136+
137+
/* Create compilation for jvmCore to prove that jvmMain does not rely on jdk8 */
138+
compilations.create('CoreMain') {
139+
/* jvmCore is automatically matched as 'defaultSourceSet' for the compilation */
140+
tasks.getByName('check').dependsOn(compileKotlinTaskProvider)
141+
}
142+
}
143+
}
144+
145+
kotlin {
107146
jvm {
108147
// For animal sniffer
109148
withJava()
110149
}
111150
}
112151

113-
114152
configurations {
115153
configureKotlinJvmPlatform(kotlinCompilerPluginClasspath)
116154
}

0 commit comments

Comments
 (0)