Publish a Kotlin Multiplatform Library to Artifacts
This guide walks you through publishing a Kotlin Multiplatform (KMP) library to Artifacts. If you're starting from the official Kotlin Multiplatform Library Template, you'll see exactly what to change.
Artifacts vs. Maven Central: Maven Central requires GPG signing, a Sonatype account, and a multi-step staging/release process. With Artifacts, you just point Gradle at your registry URL and publish with an API token. No signing, no staging, no waiting for sync.
Prerequisites
Before you begin, make sure you have:
- An Artifacts account — Register here if you don't have one
- A repository — Create one from your Dashboard (choose Maven as the package type)
- An API token — Generate one in Settings > API Tokens with
writepermission for your repo
Configure your project
The KMP Wizard template comes with the Vanniktech Maven Publish Plugin pre-configured for Maven Central. Since Vanniktech is built on top of Gradle's maven-publish plugin, we can keep it and just retarget it at Artifacts.
1. Update the mavenPublishing block
In your library module's build.gradle.kts, remove publishToMavenCentral() and signAllPublications() from the mavenPublishing block — Artifacts doesn't require GPG signing or Sonatype staging:
// library/build.gradle.kts
mavenPublishing {
// Remove these two lines:
// publishToMavenCentral()
// signAllPublications()
coordinates(group.toString(), "library", version.toString())
// POM metadata is optional for Artifacts, but you can keep it
// if you also publish to Maven Central or want it in the POM files.
}
2. Add the Artifacts repository
Add a publishing block to point at your Artifacts registry. This works because Vanniktech applies maven-publish under the hood:
// library/build.gradle.kts
publishing {
repositories {
maven {
name = "Artifacts"
// Replace YOUR_REPO with your repository name
url = uri("https://artifacts.premex.se/api/maven/YOUR_REPO/")
credentials {
username = "token"
password = findProperty("artifacts.token") as String? ?: ""
}
}
}
}
Tip: If you don't need Vanniktech at all, you can remove it and rely on
maven-publishdirectly (which the Kotlin Multiplatform plugin already applies). Thepublishing { repositories { ... } }block is all you need.
Set up authentication
You need to provide your API token to Gradle. There are two approaches:
Option A: gradle.properties (local development)
Add to your ~/.gradle/gradle.properties (user-level, not committed to git):
artifacts.token=art_your_token_here
Option B: Environment variable (CI/CD)
export ARTIFACTS_TOKEN=art_your_token_here
Then reference it in your build script:
credentials {
username = "token"
password = findProperty("artifacts.token") as String?
?: System.getenv("ARTIFACTS_TOKEN")
?: ""
}
Publish
That's it for configuration. Publish all variants with:
./gradlew publish
Gradle's maven-publish plugin will automatically publish all KMP targets (JVM, iOS, Linux, etc.) along with the Kotlin metadata module to your Artifacts repository.
You should see output like:
> Task :library:publishKotlinMultiplatformPublicationToArtifactsRepository
> Task :library:publishJvmPublicationToArtifactsRepository
> Task :library:publishIosArm64PublicationToArtifactsRepository
...
BUILD SUCCESSFUL
Verify the package is available by visiting your repository in the Artifacts web UI, or by browsing the package list.
Publish from CI/CD
Here's a GitHub Actions workflow that publishes on every tag push:
# .github/workflows/publish.yml
name: Publish to Artifacts
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Publish
run: ./gradlew publish
env:
ARTIFACTS_TOKEN: ${{ secrets.ARTIFACTS_TOKEN }}
Add your API token as a repository secret named ARTIFACTS_TOKEN in your GitHub repo settings.
Consume the library
Other projects can depend on your library by adding your Artifacts repository to their Gradle configuration.
In settings.gradle.kts
dependencyResolutionManagement {
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.premex.se/api/maven/YOUR_REPO/")
credentials {
username = "token"
password = providers.gradleProperty("artifacts.token").getOrElse("")
}
}
}
}
In your module's build.gradle.kts
dependencies {
implementation("com.example:library:1.0.0")
}
For KMP consumers, the metadata module resolves the right target automatically — just add the dependency in commonMain:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.example:library:1.0.0")
}
}
}
Next steps
- Set Up a KMP Repository — Configure the auto-build pipeline that generates npm and Swift packages from your Maven library
- API Tokens — Create scoped tokens with read-only access for consumers and write access only for your CI pipeline.
- Team Access — Invite collaborators to your repository with role-based permissions (read, write, admin).