@@ -19,23 +19,41 @@ apply from: rootProject.file('gradle/publish.gradle')
19
19
/* ==========================================================================
20
20
Configure source sets structure for kotlinx-coroutines-core:
21
21
22
- TARGETS SOURCE SETS
23
- ------- ----------------------------------------------
22
+ TARGETS SOURCE SETS
23
+ ------- ----------------------------------------------
24
24
25
25
js -----------------------------------------------------+
26
26
|
27
27
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 ---+
32
33
tvos | ^
33
34
watchos / |
34
35
|
35
36
linux \ ---> nativeOther -------+
36
37
mingw /
37
38
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
+ ========================================================================== */
39
57
40
58
project. ext. sourceSetSuffixes = [" Main" , " Test" ]
41
59
@@ -68,15 +86,12 @@ if (rootProject.ext.native_targets_enabled) {
68
86
69
87
/* ========================================================================== */
70
88
89
+
71
90
/*
72
91
* All platform plugins and configuration magic happens here instead of build.gradle
73
92
* because JMV-only projects depend on core, thus core should always be initialized before configuration.
74
93
*/
75
94
kotlin {
76
- sourceSets. forEach {
77
- SourceSetsKt . configureMultiplatform(it)
78
- }
79
-
80
95
/*
81
96
* Configure two test runs:
82
97
* 1) New memory model, Main thread
@@ -104,13 +119,36 @@ kotlin {
104
119
}
105
120
}
106
121
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 {
107
146
jvm {
108
147
// For animal sniffer
109
148
withJava()
110
149
}
111
150
}
112
151
113
-
114
152
configurations {
115
153
configureKotlinJvmPlatform(kotlinCompilerPluginClasspath)
116
154
}
0 commit comments