diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 29eed89..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,63 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle - -name: Deploy to central - -on: workflow_dispatch - -permissions: - contents: read - -jobs: - build: - uses: ./.github/workflows/gradle.yml - deploy: - needs: build - strategy: - matrix: - include: - - target: publishIosArm64PublicationToSonatypeRepository - os: macos-latest - - target: publishAndroidReleasePublicationToSonatypeRepository - os: ubuntu-latest - - target: publishJvmPublicationToSonatypeRepository - os: ubuntu-latest - - target: publishLinuxX64PublicationToSonatypeRepository - os: ubuntu-latest - - target: publishKotlinMultiplatformPublicationToSonatypeRepository - os: ubuntu-latest - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - - name: Validate Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 - - uses: actions/cache@v3 - with: - path: | - ~/.konan - key: ${{ runner.os }}-${{ hashFiles('**/.lock') }} - - name: Import GPG key - uses: crazy-max/ghaction-import-gpg@v5 - with: - gpg_private_key: ${{ secrets.OSSRH_GPG_SECRET_KEY }} - passphrase: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - name: Gradle publish - uses: gradle/gradle-build-action@ce999babab2de1c4b649dc15f0ee67e6246c994f - with: - arguments: | - ${{ matrix.target }} - closeSonatypeStagingRepository - -Psigning.gnupg.passphrase='${{secrets.OSSRH_GPG_SECRET_KEY_PASSWORD}}' - -Psigning.gnupg.keyName='${{secrets.OSSRH_GPG_SECRET_KEY_ID}}' - -PsonatypeUsername='${{secrets.OSSRH_USERNAME}}' - -PsonatypePassword='${{secrets.OSSRH_PASSWORD}}' - diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..515213f --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,25 @@ +name: Publish +on: + release: + types: [released, prereleased] +jobs: + publish: + name: Release build and publish + runs-on: macOS-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - name: Publish to MavenCentral + run: ./gradlew publishToMavenCentral --no-configuration-cache + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }} + diff --git a/.gitignore b/.gitignore index 9872784..a9b04c1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ captures .cxx local.properties xcuserdata -.kotlin \ No newline at end of file +.kotlin +*.gpg \ No newline at end of file diff --git a/README.md b/README.md index 9ece996..635db44 100644 --- a/README.md +++ b/README.md @@ -10,49 +10,246 @@ It has only one function: generate the [Fibonacci sequence](https://en.wikipedia 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. - -## How do I build it? - -1. - [x] Clone this repository ot just [use it as template](https://github.com/Kotlin/multiplatform-library-template/generate) -1. - [ ] Edit library module name and include it in [`settings.gradle.kts`](settings.gradle.kts#L18) -1. - [ ] Edit [`groupId` and `version`](convention-plugins/src/main/kotlin/module.publication.gradle.kts#L10-L11) - 1. If you need the Android support update namespace [there](library/build.gradle.kts#L38) too - 1. If you don't need an Android support delete the [`android` section](library/build.gradle.kts#L37-L43) -1. - [ ] Edit [build targets you need](library/build.gradle.kts#L9-L21) - -At this stage, you have everything set to work with Kotlin Multiplatform. The project should be buildable (but you might need to provide actual starting values for the platforms you need). - -## How do I make it build on GitHub Actions? - -To make it work on GitHub actions, you need to update the [`matrix` section in `gradle.yml`](.github/workflows/gradle.yml#L25-L34). If you didn't change platforms in `build.gradle.kts` you don't need to touch anything. But still read it to understand how it works. - -Also, currently, it only runs tests, but you can change this behaviour as you wish by modifying `matrix` and the Gradle [build command](.github/workflows/gradle.yml#L52) - -## How do I deploy it to Maven Central? - -The most part of the job is already automated for you. However, deployment to Maven Central requires some manual work from your side. - -1. - [ ] Create an account at [Sonatype issue tracker](https://issues.sonatype.org/secure/Signup!default.jspa) -1. - [ ] [Create an issue](https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134) to create new project for you -1. - [ ] You will have to prove that you own your desired namespace -1. - [ ] Create a GPG key with `gpg --gen-key`, use the same email address you used to sign up to the Sonatype Jira -1. - [ ] Find your key id in the output of the previous command looking like `D89FAAEB4CECAFD199A2F5E612C6F735F7A9A519` -1. - [ ] Upload your key to a keyserver, for example - ```bash - gpg --send-keys --keyserver keyserver.ubuntu.com "" - ``` -1. - [ ] Now you should create secrets available to your GitHub Actions - 1. via `gh` command - ```bash - gh secret set OSSRH_GPG_SECRET_KEY -a actions --body "$(gpg --export-secret-key --armor "")" - gh secret set OSSRH_GPG_SECRET_KEY_ID -a actions --body "" - gh secret set OSSRH_GPG_SECRET_KEY_PASSWORD -a actions --body "" - gh secret set OSSRH_PASSWORD -a actions --body "" - gh secret set OSSRH_USERNAME -a actions --body "" - ``` - 1. Or via the interface in `Settings` → `Secrets and Variables` → `Actions`, same variables as in 1. -1. - [ ] Edit deployment pom parameters in [`module.publication.gradle.kts`](convention-plugins/src/main/kotlin/module.publication.gradle.kts#L25-L44) -1. - [ ] Edit deploy targets in [`deploy.yml`](.github/workflows/deploy.yml#L23-L36) -1. - [ ] Call deployment manually when ready [in Actions](../../actions/workflows/deploy.yml) → `Run Workflow` -1. - [ ] When you see in your account on https://oss.sonatype.org that everything is fine, you can release your staging repositories and add target `releaseSonatypeStagingRepository` to `deploy.yml` [after this line](.github/workflows/deploy.yml#L60). This way artifacts will be published to central automatically when tests pass. +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) + +## How to publish? + +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: + +* Set up credentials, including an account on Maven Central and a PGP key to use for signing +* Configure the publishing plugin in your library’s project +* Provide your credentials to the publishing plugin so it can sign and upload your artifacts +* Run the publication task, either locally or using continuous integration + +This guide assumes that you are: + +- Creating an open-source library +- Using macOS or Linux. If you are a Windows user, use [GnuPG or Gpg4win](https://gnupg.org/download) to generate a key pair. +- Either not registered on Maven Central yet, or have an existing account that’s suitable for [publishing to the Central Portal](https://central.sonatype.org/publish-ea/publish-ea-guide/) (created after March 12th, 2024, or migrated to the Central Portal by their support) +- Publishing your library in a GitHub repository +- Using GitHub Actions for continuous integration + +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. + +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**.** + +### Prepare accounts and credentials + +#### Register a namespace {#register-a-namespace} + +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`. + +As a first step for publishing to Maven Central, you’ll need to have a verified namespace. The `groupId` of the artifacts you publish will have to start with the name of your verified namespace. For example, if you register the `com.example` namespace, you’ll be able to publish artifacts with the `groupId` set to `com.example` or `com.example.libraryname`. + +To get started with publishing to Maven Central, sign in (or create a new account) on the [Maven Central](https://central.sonatype.com/) portal. Once signed in, navigate to [Namespaces](https://central.sonatype.com/publishing/namespaces) under your profile, and click the Add Namespace button. Here, you can register a namespace for your artifacts, either based on your GitHub account or a domain name that you own. + +**For a GitHub repository** +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: + +1. Enter io.github.`` as your namespace. For example, `io.github.kotlin-hands-on`. +2. Copy the Verification Key displayed. +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`. +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. + +**For a domain name** +To use a domain name that you own as your namespace: + +1. Enter your domain as the namespace using reverse-DNS form. If your domain is `example.com`, enter `com.example`. +2. Copy the Verification Key displayed. +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. +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. + +#### Generate a Key Pair + +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. + +To get started with signing, you’ll need to generate a key pair: + +* The **private key** is used to sign your artifacts, and should never be shared with others +* The **public key** can be used by others to validate the signature of the artifacts, and should be published + +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/): + +| `brew install gpg` | +| :---- | + +Generate a key pair with the following command, and fill in the required details when prompted. + +| `gpg --full-generate-key` | +| :---- | + +Choose the recommended defaults for the type of key to be created. You can leave these selections empty and press Enter to accept the default values. + +\> At the time of writing, this is `ECC (sign and encrypt)` with `Curve 25519`. Older versions of `gpg` might default to `RSA` with a `3072` bit key size. + +Next, you’ll be prompted to set the expiration of the key. If you choose to create a key that automatically expires after a set amount of time, you’ll need to [extend its validity](https://central.sonatype.org/publish/requirements/gpg/#dealing-with-expired-keys) when it expires. + +You will be asked for your real name, email, and a comment. You can leave the comment empty. + +| `Please select what kind of key you want:`
`(1) RSA and RSA`
`(2) DSA and Elgamal`
`(3) DSA (sign only)`
`(4) RSA (sign only)`
`(9) ECC (sign and encrypt) *default*`
`(10) ECC (sign only) `
`(14) Existing key from card`
` Your selection? 9`

`Please select which elliptic curve you want:`
`(1) Curve 25519 *default*`
`(4) NIST P-384`
`(6) Brainpool P-256`
`Your selection? 1 `

`Please specify how long the key should be valid.`
`0 = key does not expire`
` = key expires in n days`
`w = key expires in n weeks`
`m = key expires in n months`
`y = key expires in n years`
`Key is valid for? (0) 0`
`Key does not expire at all`

`Is this correct? (y/N) y `
`GnuPG needs to construct a user ID to identify your key.`| +|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| + +You will be asked for a passphrase to encrypt the key, which you have to repeat. Keep this passphrase stored securely and privately. You’ll be using it later to access the private key. + +Let’s take a look at the key we’ve created with the following command: + +| `gpg --list-keys` | +| :---- | + +The output will look something like this: + +| `pub ed25519 2024-10-06 [SC] `
` F175482952A225BFC4A07A715EE6B5F76620B385CE`
`uid [ultimate] Your name `
`sub cv25519 2024-10-06 [E]` | +| :---- | + +You’ll need to use the long alphanumerical identifier of your key displayed here in the following steps. + +#### Upload the public key + +You need to [upload the public key to a keyserver](https://central.sonatype.org/publish/requirements/gpg/#distributing-your-public-key) for it to be accepted by Maven Central. There are multiple available keyservers, we’ll use `keyserver.ubuntu.com` as a default choice. + +Run the following command to upload your public key using `gpg`, **substituting your own keyid** in the parameters: + +| `gpg --keyserver keyserver.ubuntu.com --send-keys F175482952A225BFC4A07A715EE6B5F76620B385CE` | +| :---- | + +#### Export your private key {#export-your-private-key} + +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. + +| `gpg --armor --export-secret-keys F175482952A225BFC4A07A715EE6B5F76620B385CE > key.gpg` | +| :---- | + +This will create a `key.gpg` file which contains your private key. Remember not to share this with anyone. + +If you check the contents of the file, you should see contents similar to this: + +| `-----BEGIN PGP PRIVATE KEY BLOCK-----`
`lQdGBGby2X4BEACvFj7cxScsaBpjty60ehgB6xRmt8ayt+zmgB8p+z8njF7m2XiN`
`bpD/h7ZI7FC0Db2uCU4CYdZoQVl0MNNC1Yr56Pa68qucadJhY0sFNiB63KrBUoiO `
`... SQ== =Qh2r`
`-----END PGP PRIVATE KEY BLOCK-----` | +| :---- | + +#### Generate the user token {#generate-the-user-token} + +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*. + +The output will look like the example below, containing a username and a password. Store this information securely, as it can’t be viewed again on the Central Portal. If you lose these credentials, you’ll need to generate new ones later. + +| ``
` ${server}`
` l3nfaPmz`
` `
`
` | +|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| + +### Configure the project + +#### Prepare your library project + +If you started developing your library from a template project, this is a good time to change any default names in the project to match your own library’s name. This includes the name of your library module, and the name of the root project in your top-level `build.gradle.kts` file. + +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. + +| `android {`
` namespace = "io.github.kotlinhandson.fibonacci"`
`}` | +|:-----------------------------------------------------------------------------| + +#### Set up the publishing plugin + +This guide uses [vanniktech/gradle-maven-publish-plugin](https://github.com/vanniktech/gradle-maven-publish-plugin) to help with publications to Maven Central. You can read more about the advantages of the plugin [here](https://vanniktech.github.io/gradle-maven-publish-plugin/#advantages-over-maven-publish). See the [plugin’s documentation](https://vanniktech.github.io/gradle-maven-publish-plugin/central/) to learn more about its usage and available configuration options. + +To add the plugin to your project, add the following line in the plugins block, in your library module’s `build.gradle.kts` file: + +| `plugins {`
` id("com.vanniktech.maven.publish") version "0.29.0" `
`}` | +| :---- | + +*Note: for the latest available version of the plugin, check its [releases page](https://github.com/vanniktech/gradle-maven-publish-plugin/releases).* + +In the same file, add the following configuration. Customize all these values appropriately for your library. + +| `mavenPublishing {`
` publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)`
` signAllPublications()`
` coordinates("io.github.kotlin-hands-on", "fibonacci", "1.0.8")`
` pom {`
` name = "Fibonacci library"`
` description = "A mathematics calculation library."`
` inceptionYear = "2024"`
` url = "https://github.com/kotlin-hands-on/fibonacci/"`
` licenses {`
` license {`
` name = "The Apache License, Version 2.0"`
` url = "http://www.apache.org/licenses/LICENSE-2.0.txt"`
` distribution = "http://www.apache.org/licenses/LICENSE-2.0.txt"`
` }`
` }`
` developers {`
` developer {`
` id = "kotlin-hands-on"`
` name = "Kotlin Developer Advocate"`
` url = "https://github.com/kotlin-hands-on/"`
` }`
` }`
` scm {`
` url = "https://github.com/kotlin-hands-on/fibonacci/"`
` connection "scm:git:git://github.com/kotlin-hands-on/fibonacci.git"`
` developerConnection = "scm:git:ssh://git@github.com/kotlin-hands-on/fibonacci.git"`
` }`
` }`
`}` | +|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| + +Note that it’s also possible to use Gradle properties instead. + +Some of the most important, required settings here are: + +* The `coordinates`, which specify the `groupId`, `artifactId`, and `version` of your library. +* The [license](https://central.sonatype.org/publish/requirements/#license-information) that you’re publishing your library under. +* The [developer information](https://central.sonatype.org/publish/requirements/#developer-information) which lists the authors of the library. +* [SCM (Source Code Management) information](https://central.sonatype.org/publish/requirements/#scm-information), which specifies where the sources of your library are available. + +### Publish to Maven Central from Continuous Integration + +#### Add a GitHub Actions workflow to your project + +You can set up continuous integration which builds and publishes your library for you. We’ll use [GitHub Actions](https://docs.github.com/en/actions) as an example. + +To get started, add the following workflow to your repository, in the `.github/workflows/publish.yml` file. + +| `name: Publish`
` on:`
` release:`
` types: [released, prereleased]`
` jobs:`
` publish:`
` name: Release build and publish`
` runs-on: macOS-latest`
` steps:`
` - name: Check out code`
` uses:`
` actions/checkout@v4`
` - name: Set up JDK 21`
` uses:`
` actions/setup-java@v4`
` with:`
` distribution: 'zulu'`
` java-version: 21`
` - name: Publish to MavenCentral`
` run: ./gradlew publishToMavenCentral --no-configuration-cache`
` # Note: Disable Configuration Cache because of https://github.com/gradle/gradle/issues/22779`
` env:`
` ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}`
` ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}`
` ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}`
` ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}`
` ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }}` | +| :---- | + +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. + +\> Alternatively, you could configure the workflow to [trigger when a tag is pushed](https://stackoverflow.com/a/61892639) to your repository. + +\> 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)). + +\> 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. + +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. + +### Add secrets to GitHub + +To use the keys and credentials required for publication in your GitHub Action workflow while keeping them private, you need to place those values into secrets. From your GitHub repository, go to `Settings` \> `(Security) Secrets and variables > Actions`. + +Click on the `New repository secret` button, and add the following secrets: + +- `MAVEN_CENTRAL_PASSWORD` and `MAVEN_CENTRAL_PASSWORD` are the values generated by the Central Portal website in the [Generate User Token](#generate-the-user-token) section. +- `SIGNING_KEY_ID` is **the last 8 characters** of your signing key’s identifier. +- `SIGNING_PASSWORD` is the passphrase you’ve provided when generating your signing key. +- `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. + +# + +![](/images/image5.png) + +Note again that the names used for these secrets must match those used by the workflow that accesses their values. + +#### Create a release on GitHub + +With the workflow and secrets set up, you’re now ready to [create a release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release) that will trigger the publication of your library. + +Go to your GitHub repository’s main page, and click on Releases in the menu in the right sidebar. + +![](/images/image3.png) + +Click *Draft a new release*. + +![](/images/image7.png) + +Each release creates a new tag. Set the name for the tag to be created, and set a name for the release (these may be identical). Note that setting a version here does not change the version of your coordinates configured in your `build.gradle.kts` file, so you should update that version before creating a new release. + +![](/images/image4.png) + +Double-check the branch you want to target with the release (especially if you want to release from a branch that’s different from your default), and add appropriate release notes for your new version. + +The checkboxes below allow you to mark a release as a pre-release (useful for alpha, beta, or RC versions of a library), or to set the release as the latest available one: + +![](/images/image6.png) + +Click the *Publish release* button to create the new release. This will immediately show up on your GitHub repository’s main page. + +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. + +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. + +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. + +![](/images/image2.png) + +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. Also note that the library may be available for use before the website is updated. + +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: + +| `./gradlew publishAndReleaseToMavenCentral` | +| :---- | + +**Et voilà, you have successfully published your library to Maven Central.** + +# Other resources +* [Publishing via the Central Portal](https://central.sonatype.org/publish-ea/publish-ea-guide/) +* [Gradle Maven Publish Plugin \- Publishing to Maven Central](https://vanniktech.github.io/gradle-maven-publish-plugin/central/) \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 544e7a8..c0d26d7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,5 @@ plugins { - id("root.publication") - //trick: for the same plugin versions in all sub-modules alias(libs.plugins.androidLibrary).apply(false) alias(libs.plugins.kotlinMultiplatform).apply(false) -} + alias(libs.plugins.publish) apply false +} \ No newline at end of file diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts deleted file mode 100644 index 5e77211..0000000 --- a/convention-plugins/build.gradle.kts +++ /dev/null @@ -1,7 +0,0 @@ -plugins { - `kotlin-dsl` -} - -dependencies { - implementation(libs.nexus.publish) -} \ No newline at end of file diff --git a/convention-plugins/settings.gradle.kts b/convention-plugins/settings.gradle.kts deleted file mode 100644 index ffb42e8..0000000 --- a/convention-plugins/settings.gradle.kts +++ /dev/null @@ -1,21 +0,0 @@ -pluginManagement { - repositories { - google() - gradlePluginPortal() - mavenCentral() - } -} - -dependencyResolutionManagement { - repositories { - google() - gradlePluginPortal() - mavenCentral() - } - - versionCatalogs { - create("libs") { - from(files("../gradle/libs.versions.toml")) - } - } -} \ No newline at end of file diff --git a/convention-plugins/src/main/kotlin/module.publication.gradle.kts b/convention-plugins/src/main/kotlin/module.publication.gradle.kts deleted file mode 100644 index e18c9f1..0000000 --- a/convention-plugins/src/main/kotlin/module.publication.gradle.kts +++ /dev/null @@ -1,51 +0,0 @@ -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.tasks.bundling.Jar -import org.gradle.kotlin.dsl.`maven-publish` - -plugins { - `maven-publish` - signing -} - -publishing { - // Configure all publications - publications.withType { - // Stub javadoc.jar artifact - artifact(tasks.register("${name}JavadocJar", Jar::class) { - archiveClassifier.set("javadoc") - archiveAppendix.set(this@withType.name) - }) - - // Provide artifacts information required by Maven Central - pom { - name.set("Kotlin Multiplatform library template") - description.set("Dummy library to test deployment to Maven Central") - url.set("https://github.com/Kotlin/multiplatform-library-template") - - licenses { - license { - name.set("MIT") - url.set("https://opensource.org/licenses/MIT") - } - } - developers { - developer { - id.set("JetBrains") - name.set("JetBrains Team") - organization.set("JetBrains") - organizationUrl.set("https://www.jetbrains.com") - } - } - scm { - url.set("https://github.com/Kotlin/multiplatform-library-template") - } - } - } -} - -signing { - if (project.hasProperty("signing.gnupg.keyName")) { - useGpgCmd() - sign(publishing.publications) - } -} diff --git a/convention-plugins/src/main/kotlin/root.publication.gradle.kts b/convention-plugins/src/main/kotlin/root.publication.gradle.kts deleted file mode 100644 index 12e295f..0000000 --- a/convention-plugins/src/main/kotlin/root.publication.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id("io.github.gradle-nexus.publish-plugin") -} - -allprojects { - group = "org.jetbrains.kotlinx.multiplatform-library-template" - version = "0.0.1" -} - -nexusPublishing { - // Configure maven central repository - // https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh - repositories { - sonatype { //only for users registered in Sonatype after 24 Feb 2021 - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) - } - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 13a5b6b..74bbb71 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,14 +1,13 @@ [versions] agp = "8.5.0" -kotlin = "2.0.0" -nexus-publish = "2.0.0" +kotlin = "2.0.20" android-minSdk = "24" android-compileSdk = "34" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } -nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin", version.ref = "nexus-publish" } [plugins] androidLibrary = { id = "com.android.library", version.ref = "agp" } -kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } \ No newline at end of file +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +publish = { id = "com.vanniktech.maven.publish", version = "0.29.0" } \ No newline at end of file diff --git a/images/image1.png b/images/image1.png new file mode 100644 index 0000000..cf4efb0 Binary files /dev/null and b/images/image1.png differ diff --git a/images/image2.png b/images/image2.png new file mode 100644 index 0000000..088ac0a Binary files /dev/null and b/images/image2.png differ diff --git a/images/image3.png b/images/image3.png new file mode 100644 index 0000000..64a9175 Binary files /dev/null and b/images/image3.png differ diff --git a/images/image4.png b/images/image4.png new file mode 100644 index 0000000..737d45e Binary files /dev/null and b/images/image4.png differ diff --git a/images/image5.png b/images/image5.png new file mode 100644 index 0000000..0118ec8 Binary files /dev/null and b/images/image5.png differ diff --git a/images/image6.png b/images/image6.png new file mode 100644 index 0000000..8397607 Binary files /dev/null and b/images/image6.png differ diff --git a/images/image7.png b/images/image7.png new file mode 100644 index 0000000..1687c97 Binary files /dev/null and b/images/image7.png differ diff --git a/library/build.gradle.kts b/library/build.gradle.kts index cbbd9cb..4b32369 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,10 +1,14 @@ +import com.vanniktech.maven.publish.SonatypeHost import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.JvmTarget +group = "io.github.kotlin" +version = "1.0.0" + plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidLibrary) - id("module.publication") + alias(libs.plugins.publish) } kotlin { @@ -42,3 +46,37 @@ android { minSdk = libs.versions.android.minSdk.get().toInt() } } + +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + + signAllPublications() + + coordinates("io.github.kotlin", "fibonacci", "1.0.8") + + pom { + name = "My library" + description = "A library." + inceptionYear = "2024" + url = "https://github.com/kotlin/multiplatform-library-template/" + licenses { + license { + name = "XXX" + url = "YYY" + distribution = "ZZZ" + } + } + developers { + developer { + id = "XXX" + name = "YYY" + url = "ZZZ" + } + } + scm { + url = "XXX" + connection = "YYY" + developerConnection = "ZZZ" + } + } +} diff --git a/library/src/androidMain/kotlin/fibiprops.android.kt b/library/src/androidMain/kotlin/fibiprops.android.kt index 9561333..ed4c096 100644 --- a/library/src/androidMain/kotlin/fibiprops.android.kt +++ b/library/src/androidMain/kotlin/fibiprops.android.kt @@ -1,2 +1,4 @@ +package io.github.kotlin.fibonacci + actual val firstElement: Int = 1 actual val secondElement: Int = 2 \ No newline at end of file diff --git a/library/src/androidUnitTest/kotlin/AndroidFibiTest.kt b/library/src/androidUnitTest/kotlin/AndroidFibiTest.kt index 481af37..64199be 100644 --- a/library/src/androidUnitTest/kotlin/AndroidFibiTest.kt +++ b/library/src/androidUnitTest/kotlin/AndroidFibiTest.kt @@ -1,3 +1,5 @@ +package io.github.kotlin.fibonacci + import kotlin.test.Test import kotlin.test.assertEquals @@ -5,6 +7,6 @@ class AndroidFibiTest { @Test fun `test 3rd element`() { - assertEquals(3, fibi.take(3).last()) + assertEquals(3, generateFibi().take(3).last()) } } \ No newline at end of file diff --git a/library/src/commonMain/kotlin/CustomFibi.kt b/library/src/commonMain/kotlin/CustomFibi.kt index 5b57fcc..0789d76 100644 --- a/library/src/commonMain/kotlin/CustomFibi.kt +++ b/library/src/commonMain/kotlin/CustomFibi.kt @@ -1,4 +1,6 @@ -val fibi = sequence { +package io.github.kotlin.fibonacci + +fun generateFibi() = sequence { var a = firstElement yield(a) var b = secondElement diff --git a/library/src/commonTest/kotlin/FibiTest.kt b/library/src/commonTest/kotlin/FibiTest.kt index 1b0c5db..f125be8 100644 --- a/library/src/commonTest/kotlin/FibiTest.kt +++ b/library/src/commonTest/kotlin/FibiTest.kt @@ -1,3 +1,5 @@ +package io.github.kotlin.fibonacci + import kotlin.test.Test import kotlin.test.assertEquals @@ -5,6 +7,6 @@ class FibiTest { @Test fun `test 3rd element`() { - assertEquals(firstElement + secondElement, fibi.take(3).last()) + assertEquals(firstElement + secondElement, generateFibi().take(3).last()) } } \ No newline at end of file diff --git a/library/src/iosMain/kotlin/fibiprops.ios.kt b/library/src/iosMain/kotlin/fibiprops.ios.kt index 8fb1aa0..50b67d9 100644 --- a/library/src/iosMain/kotlin/fibiprops.ios.kt +++ b/library/src/iosMain/kotlin/fibiprops.ios.kt @@ -1,2 +1,4 @@ +package io.github.kotlin.fibonacci + actual val firstElement: Int = 3 actual val secondElement: Int = 4 \ No newline at end of file diff --git a/library/src/iosTest/kotlin/IosFibiTest.kt b/library/src/iosTest/kotlin/IosFibiTest.kt index 778d22a..85f83a3 100644 --- a/library/src/iosTest/kotlin/IosFibiTest.kt +++ b/library/src/iosTest/kotlin/IosFibiTest.kt @@ -1,3 +1,5 @@ +package io.github.kotlin.fibonacci + import kotlin.test.Test import kotlin.test.assertEquals @@ -5,6 +7,6 @@ class IosFibiTest { @Test fun `test 3rd element`() { - assertEquals(7, fibi.take(3).last()) + assertEquals(7, generateFibi().take(3).last()) } } \ No newline at end of file diff --git a/library/src/jvmMain/kotlin/fibiprops.jvm.kt b/library/src/jvmMain/kotlin/fibiprops.jvm.kt index b1d5404..77e39b9 100644 --- a/library/src/jvmMain/kotlin/fibiprops.jvm.kt +++ b/library/src/jvmMain/kotlin/fibiprops.jvm.kt @@ -1,2 +1,4 @@ +package io.github.kotlin.fibonacci + actual val firstElement: Int = 2 actual val secondElement: Int = 3 \ No newline at end of file diff --git a/library/src/jvmTest/kotlin/JvmFibiTest.kt b/library/src/jvmTest/kotlin/JvmFibiTest.kt index 09dedb1..9e8825d 100644 --- a/library/src/jvmTest/kotlin/JvmFibiTest.kt +++ b/library/src/jvmTest/kotlin/JvmFibiTest.kt @@ -1,3 +1,5 @@ +package io.github.kotlin.fibonacci + import kotlin.test.Test import kotlin.test.assertEquals @@ -5,6 +7,6 @@ class JvmFibiTest { @Test fun `test 3rd element`() { - assertEquals(5, fibi.take(3).last()) + assertEquals(5, generateFibi().take(3).last()) } } \ No newline at end of file diff --git a/library/src/linuxX64Main/kotlin/fibiprops.linuxX64.kt b/library/src/linuxX64Main/kotlin/fibiprops.linuxX64.kt index 9c84ba4..7c2aefd 100644 --- a/library/src/linuxX64Main/kotlin/fibiprops.linuxX64.kt +++ b/library/src/linuxX64Main/kotlin/fibiprops.linuxX64.kt @@ -1,2 +1,4 @@ +package io.github.kotlin.fibonacci + actual val firstElement: Int = 3 actual val secondElement: Int = 5 \ No newline at end of file diff --git a/library/src/linuxX64Test/kotlin/LinuxFibiTest.kt b/library/src/linuxX64Test/kotlin/LinuxFibiTest.kt index b08b96c..ffd280d 100644 --- a/library/src/linuxX64Test/kotlin/LinuxFibiTest.kt +++ b/library/src/linuxX64Test/kotlin/LinuxFibiTest.kt @@ -1,3 +1,5 @@ +package io.github.kotlin.fibonacci + import kotlin.test.Test import kotlin.test.assertEquals @@ -5,6 +7,6 @@ class LinuxFibiTest { @Test fun `test 3rd element`() { - assertEquals(8, fibi.take(3).last()) + assertEquals(8, generateFibi().take(3).last()) } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 9be41d2..40ece38 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,5 +1,4 @@ pluginManagement { - includeBuild("convention-plugins") repositories { google() mavenCentral()