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..68658357 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 + + +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 `sourceSets {}` block of the corresponding target. + +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