Skip to content

Add top-level dependencies block for Kotlin 2.2.20 #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2-2-20-docs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions topics/development/multiplatform-add-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ kotlin {
</tab>
</tabs>

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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that it should be in the "Library shared for all source sets" section
Also, it could be a tip/note


## Dependency on a Kotlin library

### Standard library
Expand Down
40 changes: 40 additions & 0 deletions topics/tools/multiplatform-dsl-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we use caps-lock, it could be

Configures common dependencies (Experimental)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw it before in this table for apiVersion and languageVersion.

Copy link
Contributor

@danil-pavlov danil-pavlov Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's a good practice, plus when it's at the end, as in compiler options, it's not that scary:) but up to you


## Targets

Expand Down Expand Up @@ -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
<secondary-label ref="Experimental"/>

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:

<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">

```kotlin
kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
}
}
```

</tab>
<tab title="Groovy" group-key="groovy">

```groovy
kotlin {
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
}
}
```

</tab>
</tabs>

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
Expand Down