Interface KotlinTargetHierarchyDsl
-
- All Implemented Interfaces:
public interface KotlinTargetHierarchyDsl
-
-
Method Summary
Modifier and Type Method Description abstract Unitapply(KotlinTargetHierarchyDescriptor hierarchyDescriptor, Function1<KotlinTargetHierarchyBuilder.Root, Unit> describeExtension)abstract Unitdefault(Function1<KotlinTargetHierarchyBuilder.Root, Unit> describeExtension)Set's up a 'natural'/'default' hierarchy withing KotlinTarget's in the project. abstract Unitcustom(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 commongroup.abstract Unitandroid(Function1<KotlinAndroidTargetHierarchyDsl, Unit> configure)Configure Android specific settings within the context of KotlinTargetHierarchy. abstract KotlinAndroidTargetHierarchyDslgetAndroid()See android -
-
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 watchosLet'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
commongroup.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 iosArm64TesttargetHierarchy.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
-
android
abstract Unit android(Function1<KotlinAndroidTargetHierarchyDsl, Unit> configure)
Configure Android specific settings within the context of KotlinTargetHierarchy. The difference between Android and other targets is that the build author is free to choose the names of compilations, whereas Android is using predefined SourceSet names.
By default, Kotlin Multiplatform will set the following default dependsOn edges:
androidMain->commonMainandroidUnitTest->commonTest
In this default setup, SourceSets like
androidInstrumentedTestwill not dependOncommonTest. This API can be used to change the default behaviorThis can be done by putting the 'androidInstrumentedTest' variants into the 'test' SourceSetTree:
targetHierarchy.android { instrumentedTest.sourceSetTree.set(SourceSetTree.test) }targetHierarchy.android { instrumentedTest.sourceSetTree.set(SourceSetTree.test) unitTest.sourceSetTree.set(SourceSetTree.unitTest) // ! <- Anything *other* than 'test' }
-
getAndroid
abstract KotlinAndroidTargetHierarchyDsl getAndroid()
See android
-
-
-
-