Skip to content

Welcome to Librarian

Librarian is an opinionated toolkit to build Kotlin libraries.

Librarian:

  • publishes your KMP/Android/JVM libraries to:
  • generates versioned KDoc using Dokka
  • automates your workflows using GitHub actions:
    • pull requests
    • documentation
    • SNAPSHOTs
    • releases
  • generates a Kotlin property holding your library version
  • monitors your binary compatibility using Kotlin Binary Compatibility validator
  • configures Java and Kotlin compatibility
  • ensure your libs can be consumed with maven
  • and more!

Get started

1/4 Add it to your project

Add the Gradle plugin to your root build.gradle.kts:

plugins {
id("com.gradleup.librarian").apply(false)
}
Librarian.root(project)

2/4 Root project configuration

Add a librarian.root.properties file to the root of your repository:

# Common information for your repository
pom.groupId=com.example
pom.version=0.0.7-SNAPSHOT
pom.description=Cool library
pom.vcsUrl=https://github.com/example/cool
pom.developer=Cool library authors
pom.license=MIT
# Optional: publish to Google Cloud Storage
gcs.bucket=gradleup
gcs.prefix=m2
# Optional: configure compatibility
java.compatibility=11
kotlin.compatibility=2.0.0
# Optional: publish older versions of the Kdoc (requires them to be already published)
kdoc.olderVersions=1.0.0,2.0.0

3/4 Project specific configuration

Configure librarian in each subproject:

module/build.gradle.kts
plugins {
// no need to add librarian here, it's already on the classpath
}
// Configure librarian
Librarian.module(project)

4/4 Add the signing and publishing secrets

Add secrets to your environment:

export LIBRARIAN_SONATYPE_PASSWORD=...
export LIBRARIAN_SONATYPE_USERNAME=...
export LIBRARIAN_SIGNING_PRIVATE_KEY=...
export LIBRARIAN_SIGNING_PRIVATE_KEY_PASSWORD=...
export LIBRARIAN_GOOGLE_SERVICES_JSON=...

You can now publish the library!

Publish your library:

./gradlew librarianPublishToMavenCentral
./gradlew librarianPublishToMavenSnapshots
./gradlew librarianPublishToGcs