Interface KotlinTargetHierarchyDsl
-
- All Implemented Interfaces:
public interface KotlinTargetHierarchyDsl
-
-
Method Summary
Modifier and Type Method Description abstract Unit
apply(KotlinTargetHierarchyDescriptor hierarchyDescriptor, Function1<KotlinTargetHierarchyBuilder.Root, Unit> describeExtension)
abstract Unit
default(Function1<KotlinTargetHierarchyBuilder.Root, Unit> describeExtension)
Set's up a 'natural'/'default' hierarchy withing KotlinTarget's in the project. abstract Unit
custom(Function1<KotlinTargetHierarchyBuilder.Root, Unit> describe)
Allows to create a fully custom hierarchy (no defaults applied) Note: Using the custom hierarchy will also require to set the edges to 'commonMain' and 'commonTest' SourceSets by using the common
group.-
-
Method Detail
-
apply
abstract Unit apply(KotlinTargetHierarchyDescriptor hierarchyDescriptor, Function1<KotlinTargetHierarchyBuilder.Root, Unit> describeExtension)
-
default
abstract Unit default(Function1<KotlinTargetHierarchyBuilder.Root, Unit> describeExtension)
Set's up a 'natural'/'default' hierarchy withing KotlinTarget's in the project.
kotlin { targetHierarchy.default() // <- position of this call is not relevant! iosX64() iosArm64() linuxX64() linuxArm64() }
Will create the following SourceSets: `iosMain, iosTest, appleMain, appleTest, linuxMain, linuxTest, nativeMain, nativeTest
Hierarchy:
common | +-----------------+-------------------+ | | native ... | | | +----------------------+--------------------+-----------------------+ | | | | apple linux mingw androidNative | +-----------+------------+------------+ | | | | macos ios tvos watchos
Let's imagine we would additionally like to share code between linux and apple (unixLike)
kotlin { targetHierarchy.default { target -> group("native") { // <- we can re-declare already existing groups and connect children to it! group("unixLike") { withLinux() withApple() } } } }
- Parameters:
describeExtension
- : Additional groups can be described to extend the 'default'/'natural' hierarchy:
-
custom
abstract Unit custom(Function1<KotlinTargetHierarchyBuilder.Root, Unit> describe)
Allows to create a fully custom hierarchy (no defaults applied) Note: Using the custom hierarchy will also require to set the edges to 'commonMain' and 'commonTest' SourceSets by using the
common
group.Sharing code between iOS and a jvmTarget:
targetHierarchy.custom { common { withJvm() group("ios") { withIos() } } }
Will create two SourceSetTree using the 'common' and 'ios' groups, applied on the "test" and "main" compilations: When the following targets are specified:
jvm()
iosX64()
iosArm64()
"main" "test" commonMain commonTest | | | | +----------+----------+ +----------+----------+ | | | | iosMain jvmMain iosTest jvmTest | | +----+-----+ +----+-----+ | | | | iosX64Main iosArm64Main iosX64Test iosArm64Test
targetHierarchy.custom { common { group("ios") { withIos() } group("frontend") { withJvm() group("ios") // <- ! We can again reference the 'ios' group } group("apple") { withMacos() group("ios") // <- ! We can again reference the 'ios' group } } }
In this case, the group "ios" can be created with 'group("ios")' and later referenced with the same construction to build the tree. Applying the descriptor from the example to the following targets:
iosX64()
iosArm64()
macosX64()
jvm()
will create the following 'main' SourceSetTree:
commonMain | +------------+----------+ | | frontendMain appleMain | | +---------+------------+-----------+----------+ | | | jvmMain iosMain macosX64Main | | +----+----+ | | iosX64Main iosArm64Main
-
-
-
-