Interface KotlinTargetHierarchyDsl

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • 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