Interface KotlinHierarchyDsl

  • All Implemented Interfaces:

    
    public interface KotlinHierarchyDsl
    
                        

    A DSL to apply hierarchy templates in a Kotlin project.

    • 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
    • Method Summary

      Modifier and Type Method Description
      abstract Unit applyHierarchyTemplate(KotlinHierarchyTemplate template) Applies a given template to the project.
      abstract Unit applyHierarchyTemplate(KotlinHierarchyTemplate template, Function1<KotlinHierarchyBuilder.Root, Unit> extension) Similar to applyHierarchyTemplate, but allows extension of the provided template.
      abstract Unit applyHierarchyTemplate(Function1<KotlinHierarchyBuilder.Root, Unit> template) Allows creating a fully custom hierarchy (no defaults applied).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • applyHierarchyTemplate

         abstract Unit applyHierarchyTemplate(KotlinHierarchyTemplate template)

        Applies a given template to the project.

        Examples:

        • Manually apply the default hierarchy (See KotlinMultiplatformExtension.applyDefaultHierarchyTemplate):

        kotlin {
            applyHierarchyTemplate(KotlinHierarchyTemplate.default)
            iosX64()
            iosArm64()
            iosSimulatorArm64()
            linuxX64()
            // ...
        }
      • applyHierarchyTemplate

         abstract Unit applyHierarchyTemplate(KotlinHierarchyTemplate template, Function1<KotlinHierarchyBuilder.Root, Unit> extension)

        Similar to applyHierarchyTemplate, but allows extension of the provided template.

        Examples:

        • Add custom groups (Experimental) to additionally share code between Linux and Apple (unixLike):

        kotlin {
            applyHierarchyTemplate(KotlinHierarchyTemplate.default) {
                group("native") { // <- we can re-declare already existing groups and connect children to it!
                    group("unixLike") {
                        withLinux()
                        withApple()
                    }
                }
            }
        }
      • applyHierarchyTemplate

         abstract Unit applyHierarchyTemplate(Function1<KotlinHierarchyBuilder.Root, Unit> template)

        Allows creating a fully custom hierarchy (no defaults applied).

        **Note: ** Using the custom hierarchy requires setting the edges to 'commonMain' and 'commonTest' SourceSets by using the common group.

        Examples:

        • Share code between iOS and JVM targets:

        applyHierarchyTemplate {
            common {
                withJvm()
                group("ios") {
                    withIos()
                }
            }
        }

        This configuration creates two KotlinSourceSetTree 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
        • Create a 'diamond structure'

        applyHierarchyTemplate {
            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. Apply the descriptor from the example to the following targets:

        • iosX64()

        • iosArm64()

        • macosX64()

        • jvm()

        To create the following 'main' KotlinSourceSetTree:

                                 commonMain
                                      |
                         +------------+----------+
                         |                       |
                     frontendMain            appleMain
                         |                        |
               +---------+------------+-----------+----------+
               |                      |                      |
            jvmMain                iosMain               macosX64Main
                                      |
                                      |
                                 +----+----+
                                 |         |
                           iosX64Main   iosArm64Main