From 8305cc465f612ffd71d577f8717839dfb9b1d04f Mon Sep 17 00:00:00 2001 From: Sarah Haggarty Date: Wed, 13 Aug 2025 13:21:40 +0200 Subject: [PATCH 1/2] update: add top-level dependencies block --- .../multiplatform-add-dependencies.md | 2 + topics/tools/multiplatform-dsl-reference.md | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/topics/development/multiplatform-add-dependencies.md b/topics/development/multiplatform-add-dependencies.md index f70ee31b..cfd49a69 100644 --- a/topics/development/multiplatform-add-dependencies.md +++ b/topics/development/multiplatform-add-dependencies.md @@ -40,6 +40,8 @@ kotlin { +You can also configure common dependencies in a top-level `dependencies` block. See [Configure dependencies at the top level](multiplatform-dsl-reference.md#configure-dependencies-at-the-top-level). + ## Dependency on a Kotlin library ### Standard library diff --git a/topics/tools/multiplatform-dsl-reference.md b/topics/tools/multiplatform-dsl-reference.md index 1f699706..089beb01 100644 --- a/topics/tools/multiplatform-dsl-reference.md +++ b/topics/tools/multiplatform-dsl-reference.md @@ -42,6 +42,7 @@ Inside `kotlin {}`, you can write the following blocks: | `targets` | Lists all targets of the project. | | `sourceSets` | Configures predefined and declares custom [source sets](#source-sets) of the project. | | `compilerOptions` | Specifies common extension-level [compiler options](#compiler-options) that are used as defaults for all targets and shared source sets. | +| `dependencies` | EXPERIMENTAL. Configures [common dependencies](#configure-dependencies-at-the-top-level) for the project. | ## Targets @@ -1002,6 +1003,45 @@ kotlin { Additionally, source sets can depend on each other and form a hierarchy. In this case, the [`dependsOn()`](#source-set-parameters) relation is used. +### Configure dependencies at the top level + + +Starting with Kotlin 2.2.20, you can configure common dependencies using a top-level `dependencies {}` block. +Dependencies declared here behave as if they were added to the `commonMain` or `commonTest` source sets. + +To use the top-level `dependencies {}` block, opt in by adding the `@OptIn(ExperimentalKotlinGradlePluginApi::class)` +annotation before the block: + + + + +```kotlin +kotlin { + @OptIn(ExperimentalKotlinGradlePluginApi::class) + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%") + } +} +``` + + + + +```groovy +kotlin { + dependencies { + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%' + } +} +``` + + + + +Add platform-specific dependencies inside the appropriate source sets of the `sourceSets {}` block. + +You can share your feedback on this feature in [YouTrack](https://youtrack.jetbrains.com/issue/KT-76446). + ## Language settings The `languageSettings {}` block in a source set defines certain aspects of project analysis and compilation. Use the From 6587d1f6106eab9f6a7fb7b9742dc9fb6e095313 Mon Sep 17 00:00:00 2001 From: Sarah Haggarty Date: Mon, 18 Aug 2025 14:23:37 +0200 Subject: [PATCH 2/2] Danil review --- topics/tools/multiplatform-dsl-reference.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/topics/tools/multiplatform-dsl-reference.md b/topics/tools/multiplatform-dsl-reference.md index 089beb01..68658357 100644 --- a/topics/tools/multiplatform-dsl-reference.md +++ b/topics/tools/multiplatform-dsl-reference.md @@ -1006,8 +1006,8 @@ In this case, the [`dependsOn()`](#source-set-parameters) relation is used. ### Configure dependencies at the top level -Starting with Kotlin 2.2.20, you can configure common dependencies using a top-level `dependencies {}` block. -Dependencies declared here behave as if they were added to the `commonMain` or `commonTest` source sets. +You can configure common dependencies using a top-level `dependencies {}` block. Dependencies declared here behave as if +they were added to the `commonMain` or `commonTest` source sets. To use the top-level `dependencies {}` block, opt in by adding the `@OptIn(ExperimentalKotlinGradlePluginApi::class)` annotation before the block: @@ -1038,7 +1038,7 @@ kotlin { -Add platform-specific dependencies inside the appropriate source sets of the `sourceSets {}` block. +Add platform-specific dependencies inside the `sourceSets {}` block of the corresponding target. You can share your feedback on this feature in [YouTrack](https://youtrack.jetbrains.com/issue/KT-76446).