Skip to content

Commit f7e82c7

Browse files
authored
update: publishing library title and options (#4728)
1 parent 5778bb2 commit f7e82c7

File tree

3 files changed

+41
-96
lines changed

3 files changed

+41
-96
lines changed

docs/kr.tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
<toc-element toc-title="[Experimental DSL] Build final native binaries" hidden="true" topic="multiplatform-native-artifacts.md"/>
150150
<toc-element accepts-web-file-names="mpp-build-native-binaries.html" topic="multiplatform-build-native-binaries.md"/>
151151
</toc-element>
152-
<toc-element accepts-web-file-names="mpp-publish-lib.html" toc-title="Publish libraries" topic="multiplatform-publish-lib.md"/>
152+
<toc-element accepts-web-file-names="mpp-publish-lib.html" toc-title="Set up library publication" topic="multiplatform-publish-lib.md"/>
153153
<toc-element toc-title="Reference">
154154
<toc-element accepts-web-file-names="mpp-dsl-reference.html,mpp-supported-platforms.html,multiplatform-supported-platforms.html" topic="multiplatform-dsl-reference.md"/>
155155
<toc-element topic="multiplatform-android-layout.md"/>

docs/topics/multiplatform/multiplatform-publish-lib.md

Lines changed: 36 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
[//]: # (title: Publishing multiplatform libraries)
1+
[//]: # (title: Setting up multiplatform library publication)
22

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:
64

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).
129

13-
group = "com.example"
14-
version = "1.0"
10+
## Publishing to a local Maven repository
1511

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:
2413

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:
2817

29-
## Structure of publications
18+
```kotlin
19+
plugins {
20+
// ...
21+
id("maven-publish")
22+
}
23+
24+
group = "com.example"
25+
version = "1.0"
3026

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
3340

3441
Publications of a multiplatform library include an additional _root_ publication `kotlinMultiplatform` that stands for the
3542
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
7380
To avoid any issues during publication, publish all artifacts from a single host to avoid duplicating publications in the
7481
repository. Maven Central, for example, explicitly forbids duplicate publications and fails the process.
7582
<!-- 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:
85-
86-
<tabs group="build-script">
87-
<tab title="Kotlin" group-key="kotlin">
88-
89-
```kotlin
90-
kotlin {
91-
jvm()
92-
js()
93-
mingwX64()
94-
linuxX64()
95-
96-
val publicationsFromMainHost =
97-
listOf(jvm(), js()).map { it.name } + "kotlinMultiplatform"
98-
99-
publishing {
100-
publications {
101-
matching { it.name in publicationsFromMainHost }.all {
102-
val targetPublication = this@all
103-
tasks.withType<AbstractPublishToMaven>()
104-
.matching { it.publication == targetPublication }
105-
.configureEach { onlyIf { findProperty("isMainHost") == "true" } }
106-
}
107-
}
108-
}
109-
}
110-
```
111-
112-
</tab>
113-
<tab title="Groovy" group-key="groovy">
114-
115-
```groovy
116-
kotlin {
117-
jvm()
118-
js()
119-
mingwX64()
120-
linuxX64()
121-
122-
def publicationsFromMainHost =
123-
[jvm(), js()].collect { it.name } + "kotlinMultiplatform"
124-
125-
publishing {
126-
publications {
127-
matching { it.name in publicationsFromMainHost }.all { targetPublication ->
128-
tasks.withType(AbstractPublishToMaven)
129-
.matching { it.publication == targetPublication }
130-
.configureEach { onlyIf { findProperty("isMainHost") == "true" } }
131-
}
132-
}
133-
}
134-
}
135-
```
136-
137-
</tab>
138-
</tabs>
13983

14084
## Publish an Android library
14185

14286
To publish an Android library, you need to provide additional configuration.
14387

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),
14589
specify the variant names in the Android target block in the `shared/build.gradle.kts` file:
14690

14791
```kotlin
@@ -153,7 +97,7 @@ kotlin {
15397

15498
```
15599

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).
157101
For a library with product flavors, the variant names also contain the flavors, like `fooBarDebug` or `fooBarRelease`.
158102

159103
The default publishing setup is as follows:
@@ -248,5 +192,5 @@ Libraries that meet the criteria are added automatically. For more information o
248192

249193
## What's next
250194

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)

docs/topics/multiplatform/multiplatform-share-on-platforms.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ you can work with third-party native libraries consumed with the [`cinterop` mec
7070

7171
## What's next?
7272

73-
* Check out examples of code sharing using the Kotlin mechanism of [expect and actual declarations](multiplatform-expect-actual.md)
74-
* Learn more about [hierarchical project structure](multiplatform-hierarchy.md)
75-
* See our recommendations on [naming source files in multiplatform projects](coding-conventions.md#source-file-names)
73+
* [Read about the Kotlin's mechanism of expected and actual declarations](multiplatform-expect-actual.md)
74+
* [Learn more about hierarchical project structure](multiplatform-hierarchy.md)
75+
* [Set up the publication of your multiplatform library](multiplatform-publish-lib.md)
76+
* [See our recommendations on naming source files in multiplatform projects](coding-conventions.md#source-file-names)

0 commit comments

Comments
 (0)