Advanced concepts of the multiplatform project structure

Edit pageLast modified: 25 September 2024

This article explains advanced concepts of the Kotlin Multiplatform project structure and how they map to the Gradle implementation. This information will be useful if you need to work with low-level abstractions of the Gradle build (configurations, tasks, publications, and others) or are creating a Gradle plugin for Kotlin Multiplatform builds.

This page can be useful if you:

  • Need to share code among a set of targets for which Kotlin doesn't create a source set.

  • Want to create a Gradle plugin for Kotlin Multiplatform builds, or need to work with low-level abstractions of the Gradle build, such as configurations, tasks, publications, and others.

One of the crucial things to understand about dependency management in a multiplatform project is the difference between Gradle-style project or library dependencies and the dependsOn relation between source sets that is specific to Kotlin:

  • dependsOn is a relation between common and platform-specific source sets that enables source set hierarchy and sharing code in multiplatform projects in general. For default source sets the hierarchy is managed automatically, but you may need to alter it in specific circumstances.

  • Library and project dependencies in general work as usual, but to properly manage them in a multiplatform project you should understand how Gradle dependencies are resolved into granular source set → source set dependencies used for compilation.