Kotlin Help

Understand Multiplatform project structure

Discover main parts of your multiplatform project:

Multiplatform plugin

When you create a multiplatform project, the Project Wizard automatically applies the kotlin-multiplatform Gradle plugin in the file build.gradle(.kts).

You can also apply it manually.

plugins { kotlin("multiplatform") version "1.9.10" }
plugins { id 'org.jetbrains.kotlin.multiplatform' version '1.9.10' }

The kotlin-multiplatform plugin configures the project for creating an application or library to work on multiple platforms and prepares it for building on these platforms.

In the file build.gradle(.kts), it creates the kotlin extension at the top level, which includes configuration for targets, source sets, and dependencies.


A multiplatform project is aimed at multiple platforms that are represented by different targets. A target is part of the build that is responsible for building, testing, and packaging the application for a specific platform, such as macOS, iOS, or Android. See the list of supported platforms.

When you create a multiplatform project, targets are added to the kotlin block in the file build.gradle(.kts).

kotlin { jvm() js(IR) { browser {} } }

Learn how to set up targets manually.

Source sets

The project includes the directory src with Kotlin source sets, which are collections of Kotlin code files, along with their resources, dependencies, and language settings. A source set can be used in Kotlin compilations for one or more target platforms.

Each source set directory includes Kotlin code files (the kotlin directory) and resources. The Project Wizard creates default source sets for the main and test compilations of the common code and all added targets.

Source sets

Source sets are added to the sourceSets block of the top-level kotlin block. For example, this is the source sets structure you get when creating a multiplatform library with the IntelliJ IDEA project wizard:

kotlin { sourceSets { val commonMain by getting val commonTest by getting { dependencies { implementation(kotlin("test")) } } val jvmMain by getting val jvmTest by getting val jsMain by getting val jsTest by getting val nativeMain by getting val nativeTest by getting } }
kotlin { sourceSets { commonMain { } commonTest { dependencies { implementation kotlin('test') } } jvmMain { } jvmTest { } jsMain { } jsTest { } nativeMain { } nativeTest { } } }

Source sets form a hierarchy, which is used for sharing the common code. In a source set shared among several targets, you can use the platform-specific language features and dependencies that are available for all these targets.

For example, all Kotlin/Native features are available in the desktopMain source set, which targets the Linux (linuxX64), Windows (mingwX64), and macOS (macosX64) platforms.

Hierarchical structure

Learn how to build the hierarchy of source sets.


Each target can have one or more compilations, for example, for production and test purposes.

For each target, default compilations include:

  • main and test compilations for JVM, JS, and Native targets.

  • A compilation per Android build variant, for Android targets.


Each compilation has a default source set, which contains sources and dependencies specific to that compilation.

Learn how to configure compilations.

Last modified: 28 August 2023