Skip to content

Commit 4e78e03

Browse files
authored
Merge pull request #36 from Kotlin/readme_update
README tidying
2 parents 0bc4fbd + 174a199 commit 4e78e03

File tree

2 files changed

+51
-42
lines changed

2 files changed

+51
-42
lines changed

README.md

+50-41
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
[![official project](http://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
1+
[![official project](http://jb.gg/badges/official.svg)](https://github.com/JetBrains#jetbrains-on-github)
22

33
# Multiplatform library template
44

55
## What is it?
66

7-
It is the barebones library project intended to quickly bootstrap a Kotlin Multiplatform library, that is deployable to Maven Central.
7+
This repository contains a simple library project, intended to demonstrate a [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html) library that is deployable to [Maven Central](https://central.sonatype.com/).
88

9-
It has only one function: generate the [Fibonacci sequence](https://en.wikipedia.org/wiki/Fibonacci_sequence) starting from platform-provided numbers. Also, it has a test for each platform just to be sure that tests run.
9+
The library has only one function: generate the [Fibonacci sequence](https://en.wikipedia.org/wiki/Fibonacci_sequence) starting from platform-provided numbers. Also, it has a test for each platform just to be sure that tests run.
1010

11-
Note that no other actions or tools usually required for the library development are set up, such as [tracking of backwards compatibility]
12-
(https://kotlinlang.org/docs/jvm-api-guidelines-backward-compatibility.html#tools-designed-to-enforce-backward-compatibility), explicit API mode,
13-
licensing, contribution guideline, code of conduct and others. You can find a guide for best practices for designing Kotlin libraries [here.](https://kotlinlang.org/docs/api-guidelines-introduction.html)
11+
Note that no other actions or tools usually required for the library development are set up, such as [tracking of backwards compatibility](https://kotlinlang.org/docs/jvm-api-guidelines-backward-compatibility.html#tools-designed-to-enforce-backward-compatibility), explicit API mode, licensing, contribution guideline, code of conduct and others. You can find a guide for best practices for designing Kotlin libraries [here](https://kotlinlang.org/docs/api-guidelines-introduction.html).
1412

1513
## How to publish?
1614

1715
This guide describes the steps of publishing a library built with Kotlin Multiplatform to the [Maven Central repository](https://central.sonatype.com/). To publish your library, you’ll need to:
1816

19-
* Set up credentials, including an account on Maven Central and a PGP key to use for signing
20-
* Configure the publishing plugin in your library’s project
21-
* Provide your credentials to the publishing plugin so it can sign and upload your artifacts
22-
* Run the publication task, either locally or using continuous integration
17+
* Set up credentials, including an account on Maven Central and a PGP key to use for signing.
18+
* Configure the publishing plugin in your library’s project.
19+
* Provide your credentials to the publishing plugin so it can sign and upload your artifacts.
20+
* Run the publication task, either locally or using continuous integration.
2321

2422
This guide assumes that you are:
2523

@@ -31,11 +29,11 @@ This guide assumes that you are:
3129

3230
Most of the steps here are still applicable if you’re using a different setup, but there might be some differences you need to account for. An [important limitation](https://kotlinlang.org/docs/multiplatform-publish-lib.html#host-requirements) is that Apple targets must be built on a machine with macOS.
3331

34-
Throughout this guide, we’ll use the [https://github.com/kotlin-hands-on/fibonacci](https://github.com/kotlin-hands-on/fibonacci) repository as an example. You can refer to the code of this repository to see how the publishing setup works. Don’t forget to **replace all example values with your own** as you’re configuring your project.
32+
Throughout this guide, we’ll use the [https://github.com/kotlin-hands-on/fibonacci](https://github.com/kotlin-hands-on/fibonacci) repository as an example. You can refer to the code of this repository to see how the publishing setup works. You **must replace all example values with your own** as you’re configuring your project.
3533

3634
### Prepare accounts and credentials
3735

38-
#### Register a namespace {#register-a-namespace}
36+
#### Register a namespace
3937

4038
Artifacts published to Maven repositories are identified by their coordinates, for example `com.example:library:1.0.0`. These coordinates are made up of three parts, separated by colons: the `groupId`, `artifactId`, and `version`.
4139

@@ -46,27 +44,27 @@ To get started with publishing to Maven Central, sign in (or create a new accoun
4644
**For a GitHub repository**
4745
Using your GitHub account to create a namespace is a good option if you don’t own a domain name to use for publication. To create a namespace based on your GitHub account:
4846

49-
1. Enter io.github.`<your username>` as your namespace. For example, `io.github.kotlin-hands-on`.
47+
1. Enter `io.github.<your username>` as your namespace. For example, `io.github.kotlin-hands-on`.
5048
2. Copy the Verification Key displayed.
5149
3. On GitHub, create a new repository with your GitHub account with the verification key as the repository’s name. For example, `http://github.com/kotlin-hands-on/ex4mpl3c0d`.
52-
4. Navigate back to Maven Central, and click on the Verify Namespace button. After a successful verification, you can delete the repository you’ve created.
50+
4. Navigate back to Maven Central, and click on the Verify Namespace button. After verification succeeds you can delete the repository you’ve created.
5351

5452
**For a domain name**
5553
To use a domain name that you own as your namespace:
5654

57-
1. Enter your domain as the namespace using reverse-DNS form. If your domain is `example.com`, enter `com.example`.
55+
1. Enter your domain as the namespace using a reverse-DNS form. If your domain is `example.com`, enter `com.example`.
5856
2. Copy the Verification Key displayed.
5957
3. Create a new DNS TXT record with the verification key as its contents. See [Maven Central’s FAQ](https://central.sonatype.org/faq/how-to-set-txt-record/) for more information on how to do this with various domain registrars.
60-
4. Navigate back to Maven Central, and click on the Verify Namespace button. After a successful verification, you can delete the TXT record you’ve created.
58+
4. Navigate back to Maven Central, and click on the Verify Namespace button. After verification succeeds you can delete the TXT record you’ve created.
6159

6260
#### Generate a Key Pair
6361

6462
Artifacts published to Maven Central [must be signed with a PGP signature](https://central.sonatype.org/publish/requirements/gpg/), which allows users to validate the origin of artifacts.
6563

6664
To get started with signing, you’ll need to generate a key pair:
6765

68-
* The **private key** is used to sign your artifacts, and should never be shared with others
69-
* The **public key** can be used by others to validate the signature of the artifacts, and should be published
66+
* The **private key** is used to sign your artifacts, and should never be shared with others.
67+
* The **public key** can be used by others to validate the signature of the artifacts, and should be published.
7068

7169
The `gpg` tool that can manage signatures for you is available from [their website](https://gnupg.org/download/index.html). You can also install it using package managers such as [Homebrew](https://brew.sh/):
7270

@@ -88,7 +86,7 @@ Next, you’ll be prompted to set the expiration of the key. If you choose to cr
8886

8987
You will be asked for your real name, email, and a comment. You can leave the comment empty.
9088

91-
```bash
89+
```text
9290
Please select what kind of key you want:
9391
(1) RSA and RSA
9492
(2) DSA and Elgamal
@@ -98,6 +96,7 @@ Please select what kind of key you want:
9896
(10) ECC (sign only)
9997
(14) Existing key from card
10098
Your selection? 9
99+
101100
Please select which elliptic curve you want:
102101
(1) Curve 25519 *default*
103102
(4) NIST P-384
@@ -113,7 +112,7 @@ Please specify how long the key should be valid.
113112
Key is valid for? (0) 0
114113
Key does not expire at all
115114
116-
`Is this correct? (y/N) y
115+
Is this correct? (y/N) y
117116
GnuPG needs to construct a user ID to identify your key.
118117
```
119118

@@ -127,7 +126,7 @@ gpg --list-keys
127126

128127
The output will look something like this:
129128

130-
```bash
129+
```text
131130
pub ed25519 2024-10-06 [SC]
132131
F175482952A225BFC4A07A715EE6B5F76620B385CE
133132
uid [ultimate] Your name <your email address>
@@ -146,27 +145,30 @@ Run the following command to upload your public key using `gpg`, **substituting
146145
gpg --keyserver keyserver.ubuntu.com --send-keys F175482952A225BFC4A07A715EE6B5F76620B385CE
147146
```
148147

149-
#### Export your private key {#export-your-private-key}
148+
#### Export your private key
150149

151150
To let your Gradle project access your private key, you’ll need to export it to a file. Use the following command, **passing in your own keyid** as a parameter. You will be prompted to enter the passphrase you’ve used when creating the key.
152151

153152
```bash
154153
gpg --armor --export-secret-keys F175482952A225BFC4A07A715EE6B5F76620B385CE > key.gpg
155154
```
156155

157-
This will create a `key.gpg` file which contains your private key. Remember not to share this with anyone.
156+
This will create a `key.gpg` file which contains your private key.
157+
158+
> [!CAUTION]
159+
> Never share a private key with anyone.
158160
159161
If you check the contents of the file, you should see contents similar to this:
160162

161-
```bash
163+
```text
162164
-----BEGIN PGP PRIVATE KEY BLOCK-----
163165
lQdGBGby2X4BEACvFj7cxScsaBpjty60ehgB6xRmt8ayt+zmgB8p+z8njF7m2XiN
166+
...
164167
bpD/h7ZI7FC0Db2uCU4CYdZoQVl0MNNC1Yr56Pa68qucadJhY0sFNiB63KrBUoiO
165-
... SQ== =Qh2r
166168
-----END PGP PRIVATE KEY BLOCK-----
167169
```
168170

169-
#### Generate the user token {#generate-the-user-token}
171+
#### Generate the user token
170172

171173
Your project will also need to authenticate with Maven Central to upload artifacts. On the Central Portal, navigate to the [Account](https://central.sonatype.com/account) page, and click on *Generate User Token*.
172174

@@ -176,7 +178,7 @@ The output will look like the example below, containing a username and a passwor
176178
<server>
177179
<id>${server}</id>
178180
<username>l3nfaPmz</username>
179-
<password<gh9jT9XfnGtUngWTZwTu/8241keYdmQpipqLPRKeDLTh</password>
181+
<password>gh9jT9XfnGtUngWTZwTu/8241keYdmQpipqLPRKeDLTh</password>
180182
</server>
181183
```
182184

@@ -189,6 +191,8 @@ If you started developing your library from a template project, this is a good t
189191
If you have an Android target in your project, you should follow the [steps to prepare your Android library release](https://developer.android.com/build/publish-library/prep-lib-release). This, at a minimum, requires you to [specify an appropriate namespace](https://developer.android.com/build/publish-library/prep-lib-release#choose-namespace) for your library, so that a unique R class will be generated when their resources are compiled. Notice that the namespace is different from the Maven namespace created in the [Register a namespace](#register-a-namespace) section above.
190192

191193
```kotlin
194+
// build.gradle.kts
195+
192196
android {
193197
namespace = "io.github.kotlinhandson.fibonacci"
194198
}
@@ -201,6 +205,8 @@ This guide uses [vanniktech/gradle-maven-publish-plugin](https://github.com/vann
201205
To add the plugin to your project, add the following line in the plugins block, in your library module’s `build.gradle.kts` file:
202206

203207
```kotlin
208+
// build.gradle.kts
209+
204210
plugins {
205211
id("com.vanniktech.maven.publish") version "0.29.0"
206212
}
@@ -211,6 +217,8 @@ plugins {
211217
In the same file, add the following configuration. Customize all these values appropriately for your library.
212218

213219
```kotlin
220+
// build.gradle.kts
221+
214222
mavenPublishing {
215223
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
216224

@@ -226,8 +234,8 @@ mavenPublishing {
226234
licenses {
227235
license {
228236
name = "The Apache License, Version 2.0"
229-
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
230-
distribution = "http://www.apache.org/licenses/LICENSE-2.0.txt"
237+
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
238+
distribution = "https://www.apache.org/licenses/LICENSE-2.0.txt"
231239
}
232240
}
233241
developers {
@@ -239,7 +247,7 @@ mavenPublishing {
239247
}
240248
scm {
241249
url = "https://github.com/kotlin-hands-on/fibonacci/"
242-
connection "scm:git:git://github.com/kotlin-hands-on/fibonacci.git"`
250+
connection = "scm:git:git://github.com/kotlin-hands-on/fibonacci.git"
243251
developerConnection = "scm:git:ssh://[email protected]/kotlin-hands-on/fibonacci.git"
244252
}
245253
}
@@ -264,6 +272,8 @@ You can set up continuous integration which builds and publishes your library fo
264272
To get started, add the following workflow to your repository, in the `.github/workflows/publish.yml` file.
265273

266274
```yaml
275+
# .github/workflows/publish.yml
276+
267277
name: Publish
268278
on:
269279
release:
@@ -292,11 +302,12 @@ jobs:
292302
293303
After committing and pushing this change, this workflow will run automatically when you create a release (including a pre-release) in the GitHub repository hosting your project. It checks out the current version of your code, sets up a JDK, and then runs the `publishToMavenCentral` Gradle task.
294304

295-
\> Alternatively, you could configure the workflow to [trigger when a tag is pushed](https://stackoverflow.com/a/61892639) to your repository.
296-
297-
\> The script above disables Gradle [configuration cache](https://docs.gradle.org/current/userguide/configuration_cache.html) for the publication task by adding `--no-configuration-cache` to the Gradle command, as the publication plugin does not support it (see this [open issue](https://github.com/gradle/gradle/issues/22779)).
298-
299-
\> Reminder: When using `publishToMavenCentral`, you’ll still need to check and release your deployment manually on the website, as described in the previous section. You may use `publishAndReleaseToMavenCentral` instead for a fully automated release.
305+
> [!NOTE]
306+
> Alternatively, you could configure the workflow to [trigger when a tag is pushed](https://stackoverflow.com/a/61892639) to your repository.
307+
>
308+
> The script above disables Gradle [configuration cache](https://docs.gradle.org/current/userguide/configuration_cache.html) for the publication task by adding `--no-configuration-cache` to the Gradle command, as the publication plugin does not support it (see this [open issue](https://github.com/gradle/gradle/issues/22779)).
309+
>
310+
> Reminder: When using `publishToMavenCentral`, you’ll still need to check and release your deployment manually on the website, as described in the previous section. You may use `publishAndReleaseToMavenCentral` instead for a fully automated release.
300311

301312
This action will need your signing details and your Maven Central credentials. These will be configured as GitHub Actions secrets in the next section. The configuration of the workflow above takes these secrets and places them into environment variables, which will make them available to the Gradle build automatically.
302313

@@ -311,8 +322,6 @@ Click on the `New repository secret` button, and add the following secrets:
311322
- `SIGNING_PASSWORD` is the passphrase you’ve provided when generating your signing key.
312323
- `GPG_KEY_CONTENTS` should contain the contents of your GPG private key file, which you’ve created earlier in the [Export your private key](#export-your-private-key) section.
313324

314-
#
315-
316325
![](/images/github_secrets.png)
317326

318327
Note again that the names used for these secrets must match those used by the workflow that accesses their values.
@@ -341,18 +350,18 @@ The checkboxes below allow you to mark a release as a pre-release (useful for al
341350

342351
Click the *Publish release* button to create the new release. This will immediately show up on your GitHub repository’s main page.
343352

344-
Click the Actions tab on the top of your GitHub repository. Here you’ll see the new workflow that was triggered by the GitHub release. Click it to see the outputs of the publication task.
353+
Click the Actions tab on the top of your GitHub repository. Here you’ll see the new workflow was triggered by the GitHub release. Click it to see the outputs of the publication task.
345354

346355
After this task completes successfully, navigate to the [Deployments](https://central.sonatype.com/publishing/deployments) dashboard. You should see a new deployment here. This deployment will be in the *pending* and *validating* states for some time while Maven Central performs checks on it.
347356

348357
Once your deployment moves to a *validated* state, you should see that it contains all the artifacts you’ve uploaded. If everything looks correct, click the *Publish* button to release these artifacts.
349358

350359
![](/images/published_on_maven_central.png)
351360

352-
Note that it will take some time (about 15-30 minutes, usually) after the release for the artifacts to be available publicly on Maven Central.
361+
Note that it will take some time (about 1530 minutes, usually) after the release for the artifacts to be available publicly on Maven Central.
353362
Also note that the library may be available for use before they are indexed on [the Maven Central website](https://central.sonatype.com/).
354363

355-
There’s also another task available which both uploads and releases the artifacts automatically once the the deployment is verified, without having to manually release them on the website:
364+
There’s also another task available which both uploads and releases the artifacts automatically once the deployment is verified, without having to manually release them on the website:
356365

357366
```bash
358367
./gradlew publishAndReleaseToMavenCentral
@@ -369,4 +378,4 @@ There’s also another task available which both uploads and releases the artifa
369378

370379
# Other resources
371380
* [Publishing via the Central Portal](https://central.sonatype.org/publish-ea/publish-ea-guide/)
372-
* [Gradle Maven Publish Plugin \- Publishing to Maven Central](https://vanniktech.github.io/gradle-maven-publish-plugin/central/)
381+
* [Gradle Maven Publish Plugin \- Publishing to Maven Central](https://vanniktech.github.io/gradle-maven-publish-plugin/central/)

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ plugins {
22
alias(libs.plugins.androidLibrary) apply false
33
alias(libs.plugins.kotlinMultiplatform) apply false
44
alias(libs.plugins.vanniktech.mavenPublish) apply false
5-
}
5+
}

0 commit comments

Comments
 (0)