You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[//]: #(title: Setting up multiplatform library publication)
2
2
3
-
You can publish a multiplatform library to a local Maven repository with the [`maven-publish` Gradle plugin](https://docs.gradle.org/current/userguide/publishing_maven.html).
4
-
In the `shared/build.gradle.kts` file, specify the group, version, and the [repositories](https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories) where the library
5
-
should be published. The plugin creates publications automatically.
3
+
You can set up the publication of your multiplatform library to different locations:
6
4
7
-
```kotlin
8
-
plugins {
9
-
//...
10
-
id("maven-publish")
11
-
}
5
+
*[To a local Maven repository](#publishing-to-a-local-maven-repository)
6
+
* To the Maven Central repository. Learn how to set up account credentials, customize library metadata, and configure
7
+
the publication plugin in [our tutorial](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-publish-libraries.html).
8
+
* To a GitHub repository. For more information, see GitHub's documentation on [GitHub packages](https://docs.github.com/en/packages).
12
9
13
-
group ="com.example"
14
-
version ="1.0"
10
+
## Publishing to a local Maven repository
15
11
16
-
publishing {
17
-
repositories {
18
-
maven {
19
-
//...
20
-
}
21
-
}
22
-
}
23
-
```
12
+
You can publish a multiplatform library to a local Maven repository with the `maven-publish` Gradle plugin:
24
13
25
-
> You can also publish a multiplatform library to a GitHub repository. For more information, see GitHub's documentation on [GitHub packages](https://docs.github.com/en/packages).
26
-
>
27
-
{style="tip"}
14
+
1. In the `shared/build.gradle.kts` file, add the [`maven-publish` Gradle plugin](https://docs.gradle.org/current/userguide/publishing_maven.html).
15
+
2. Specify the group and version for the library, as well as the [repositories](https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories)
16
+
where it should be published:
28
17
29
-
## Structure of publications
18
+
```kotlin
19
+
plugins {
20
+
// ...
21
+
id("maven-publish")
22
+
}
23
+
24
+
group ="com.example"
25
+
version ="1.0"
30
26
31
-
When used with `maven-publish`, the Kotlin plugin automatically creates publications for each target that can be built on the current host, except for the Android target,
32
-
which needs an [additional step to configure publishing](#publish-an-android-library).
27
+
publishing {
28
+
repositories {
29
+
maven {
30
+
//...
31
+
}
32
+
}
33
+
}
34
+
```
35
+
36
+
When used with `maven-publish`, the Kotlin plugin automatically creates publications for each target that can be built
37
+
on the current host, except for the Android target, which needs an [additional step to configure publishing](#publish-an-android-library).
38
+
39
+
## Structure of publications
33
40
34
41
Publications of a multiplatform library include an additional _root_ publication `kotlinMultiplatform` that stands for the
35
42
whole library and is automatically resolved to the appropriate platform-specific artifacts when added as a dependency to the common source set.
@@ -73,75 +80,12 @@ Cross-compilation is currently Experimental and has some limitations. You still
73
80
To avoid any issues during publication, publish all artifacts from a single host to avoid duplicating publications in the
74
81
repository. Maven Central, for example, explicitly forbids duplicate publications and fails the process.
75
82
<!-- TBD: add the actual error -->
76
-
77
-
#### If you use Kotlin 1.7.0 or earlier {initial-collapse-state="collapsed" collapsible="true"}
78
-
79
-
Before 1.7.20, the Kotlin/Native compiler didn't support all cross-compilation options. If you use earlier versions, you may need
80
-
to publish multiplatform projects from multiple hosts: a Windows host to compile a Windows target, a Linux host to compile a Linux target, and so on.
81
-
This can result in duplicate publications of modules that are cross-compiled. The most straightforward way to avoid this is to upgrade to a later
82
-
version of Kotlin and publish from a single host as described above.
83
-
84
-
If upgrading is not an option, assign a main host for each target and check for it in the `shared/build.gradle(.kts)` file:
To publish an Android library, you need to provide additional configuration.
143
87
144
-
By default, no artifacts of an Android library are published. To publish artifacts produced by a set of [Android variants](https://developer.android.com/studio/build/build-variants),
88
+
By default, no artifacts of an Android library are published. To publish artifacts produced by a set of Android [build variants](https://developer.android.com/build/build-variants),
145
89
specify the variant names in the Android target block in the `shared/build.gradle.kts` file:
146
90
147
91
```kotlin
@@ -153,7 +97,7 @@ kotlin {
153
97
154
98
```
155
99
156
-
The example works for Android libraries without [product flavors](https://developer.android.com/studio/build/build-variants#product-flavors).
100
+
The example works for Android libraries without [product flavors](https://developer.android.com/build/build-variants#product-flavors).
157
101
For a library with product flavors, the variant names also contain the flavors, like `fooBarDebug` or `fooBarRelease`.
158
102
159
103
The default publishing setup is as follows:
@@ -248,5 +192,5 @@ Libraries that meet the criteria are added automatically. For more information o
248
192
249
193
## What's next
250
194
251
-
See the [Library authors' guidelines](api-guidelines-build-for-multiplatform.md) for best practices and tips
252
-
on designing a library for Kotlin Multiplatform.
195
+
*[Learn how to publish your Kotlin Multiplatform library to the Maven Central repository](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-publish-libraries.html)
196
+
*[See the Library authors' guidelines for best practices and tips on designing a library for Kotlin Multiplatform](api-guidelines-build-for-multiplatform.md)
0 commit comments