@@ -25,7 +25,7 @@ The Kotlin Gradle plugin has a built-in default [hierarchy template](#see-the-fu
25
25
It contains predefined intermediate source sets for some popular use cases.
26
26
The plugin sets up those source sets automatically based on the targets specified in your project.
27
27
28
- Consider the following example :
28
+ Consider the following ` build.gradle(.kts) ` file in the project's module that contains shared code :
29
29
30
30
<tabs group =" build-script " >
31
31
<tab title =" Kotlin " group-key =" kotlin " >
@@ -67,7 +67,8 @@ from the `apple`, `native`, and `common` source sets is compiled to `watchosArm6
67
67
The Kotlin Gradle plugin provides both type-safe and static accessors for all of the source sets from the default hierarchy
68
68
template, so you can reference them without ` by getting ` or ` by creating ` constructs compared to the [ manual configuration] ( #manual-configuration ) .
69
69
70
- If you try to access the source set without declaring the corresponding target first, you'll see a warning:
70
+ If you try to access the source set in the shared module's ` build.gradle(.kts) ` file without declaring the corresponding
71
+ target first, you'll see a warning:
71
72
72
73
<tabs group =" build-script " >
73
74
<tab title =" Kotlin " group-key =" kotlin " >
@@ -147,8 +148,8 @@ To solve this issue, configure your project by doing one of the following:
147
148
148
149
** Case** . All of your intermediate source sets are currently covered by the default hierarchy template.
149
150
150
- ** Solution** . Remove all manual ` dependsOn() ` calls and source sets with ` by creating ` constructions.
151
- To check the list of all default source sets, see the [ full hierarchy template] ( #see-the-full-hierarchy-template ) .
151
+ ** Solution** . In the shared module's ` build.gradle(.kts) ` file, remove all manual ` dependsOn() ` calls and source sets
152
+ with ` by creating ` constructions. To check the list of all default source sets, see the [ full hierarchy template] ( #see-the-full-hierarchy-template ) .
152
153
153
154
#### Creating additional source sets
154
155
@@ -157,7 +158,7 @@ for example, one between a macOS and a JVM target.
157
158
158
159
** Solution** :
159
160
160
- 1 . Reapply the template by explicitly calling ` applyDefaultHierarchyTemplate() ` .
161
+ 1 . In the shared module's ` build.gradle(.kts) ` file, reapply the template by explicitly calling ` applyDefaultHierarchyTemplate() ` .
161
162
2 . Configure additional source sets [ manually] ( #manual-configuration ) using ` dependsOn() ` :
162
163
163
164
<tabs group =" build-script " >
@@ -258,61 +259,63 @@ the plugin picks the shared source sets based on the specified targets from the
258
259
You can manually introduce an intermediate source in the source set structure.
259
260
It will hold the shared code for several targets.
260
261
261
- For example, here’ s what to do if you want to share code among native Linux,
262
+ For example, here' s what to do if you want to share code among native Linux ,
262
263
Windows , and macOS targets (`linuxX64`, `mingwX64`, and `macosX64`):
263
264
264
- 1. Add the intermediate source set `desktopMain`, which holds the shared logic for these targets.
265
- 2. Specify the source set hierarchy using the `dependsOn` relation.
265
+ 1 . In the shared module' s `build.gradle(.kts)` file, add the intermediate source set `desktopMain`, which holds the shared
266
+ logic for these targets.
267
+ 2. Using the `dependsOn` relation, set up the source set hierarchy. Connect `commonMain` with `desktopMain` and then
268
+ `desktopMain` with each of the target source sets:
266
269
267
- <tabs group="build-script">
268
- <tab title="Kotlin" group-key="kotlin">
269
-
270
- ```kotlin
271
- kotlin {
272
- linuxX64()
273
- mingwX64()
274
- macosX64()
275
-
276
- sourceSets {
277
- val desktopMain by creating {
278
- dependsOn(commonMain.get())
270
+ <tabs group="build-script">
271
+ <tab title="Kotlin" group-key="kotlin">
272
+
273
+ ```kotlin
274
+ kotlin {
275
+ linuxX64()
276
+ mingwX64()
277
+ macosX64()
278
+
279
+ sourceSets {
280
+ val desktopMain by creating {
281
+ dependsOn(commonMain.get())
282
+ }
283
+
284
+ linuxX64Main.get().dependsOn(desktopMain)
285
+ mingwX64Main.get().dependsOn(desktopMain)
286
+ macosX64Main.get().dependsOn(desktopMain)
279
287
}
280
-
281
- linuxX64Main.get().dependsOn(desktopMain)
282
- mingwX64Main.get().dependsOn(desktopMain)
283
- macosX64Main.get().dependsOn(desktopMain)
284
288
}
285
- }
286
- ```
287
-
288
- </ tab>
289
- <tab title="Groovy" group-key="groovy">
290
-
291
- ```groovy
292
- kotlin {
293
- linuxX64 ()
294
- mingwX64 ()
295
- macosX64()
296
-
297
- sourceSets {
298
- desktopMain {
299
- dependsOn(commonMain.get())
300
- }
301
- linuxX64Main {
302
- dependsOn(desktopMain)
303
- }
304
- mingwX64Main {
305
- dependsOn(desktopMain)
306
- }
307
- macosX64Main {
308
- dependsOn(desktopMain)
289
+ ```
290
+
291
+ </tab>
292
+ < tab title="Groovy" group-key="groovy" >
293
+
294
+ ```groovy
295
+ kotlin {
296
+ linuxX64()
297
+ mingwX64 ()
298
+ macosX64 ()
299
+
300
+ sourceSets {
301
+ desktopMain {
302
+ dependsOn(commonMain.get())
303
+ }
304
+ linuxX64Main {
305
+ dependsOn(desktopMain)
306
+ }
307
+ mingwX64Main {
308
+ dependsOn(desktopMain)
309
+ }
310
+ macosX64Main {
311
+ dependsOn(desktopMain)
312
+ }
309
313
}
310
314
}
311
- }
312
- ```
313
-
314
- </tab>
315
- </tabs>
315
+ ```
316
+
317
+ </tab>
318
+ </tabs>
316
319
317
320
The resulting hierarchical structure will look like this:
318
321
0 commit comments