Skip to content

auxDK/central-publishing-plugin

Repository files navigation

Publish

Is a Gradle plugin for Android library projects. It helps you publish your Android library to Maven Central.

Plugin id:

id("io.github.auxdk.publish") version "0.1.2"

What The Plugin Does

The plugin configures these parts for you:

  • maven-publish
  • Android release publication
  • sources jar
  • javadoc jar
  • local Maven test repository
  • Maven Central snapshot publishing
  • Maven Central Portal bundle zip
  • GPG signatures for release files
  • upload to Maven Central Portal

The plugin is made for Android libraries, not Android apps.

Gradle Feature Compatibility

The plugin currently declares Configuration Cache as not supported. Its publishing tasks run local GPG signing and Maven Central Portal upload steps.

Requirements

You need:

  • an Android library project
  • Gradle
  • Android Gradle Plugin
  • a Maven Central account
  • a Central Portal user token
  • GPG installed on your machine
  • a GPG key that is published to a public key server

Add The Plugin

In settings.gradle.kts, use gradlePluginPortal():

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "my-library"
include(":library")

In your Android library module, for example library/build.gradle.kts:

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.android")
    id("io.github.auxdk.publish") version "0.1.2"
}

group = "io.github.myname"
version = "1.0.0"

android {
    namespace = "io.github.myname.mylibrary"
    compileSdk = 36

    defaultConfig {
        minSdk = 23
    }
}

mavenCentralPublishing {
    pomName.set("My Library")
    pomDescription.set("A small Android library.")
    pomUrl.set("https://github.com/myname/my-library")

    developerId.set("myname")
    developerName.set("My Name")
    developerEmail.set("me@example.com")

    scmConnection.set("scm:git:https://github.com/myname/my-library.git")
    scmDeveloperConnection.set("scm:git:ssh://git@github.com/myname/my-library.git")
    scmUrl.set("https://github.com/myname/my-library")
}

Configure Secrets

Add your secrets to local.properties. Do not commit this file.

sdk.dir=/Users/me/Library/Android/sdk

centralPortalUsername=your-central-portal-token-username
centralPortalPassword=your-central-portal-token-password

signingKeyId=YOUR_GPG_KEY_ID

You can also use one token value instead of username and password:

centralPortalToken=base64(username:password)

The plugin reads local.properties from the root project.

Check Your GPG Key

Check that GPG works:

gpg --list-secret-keys --keyid-format LONG

You must have a secret key on your machine. The public key must be available on a public key server.

The plugin signs files with:

gpg --batch --yes --armor --detach-sign

If you set signingKeyId, the plugin also uses:

--local-user YOUR_GPG_KEY_ID

Test Locally First

Publish to your local Maven cache:

./gradlew publishToMavenLocal

This is good for a quick test in another local project.

You can also publish to a local folder:

./gradlew publishAllPublicationsToLocalReleaseRepository

The files are created in:

build/repo

Publish A Snapshot

For a snapshot version, your version must end with -SNAPSHOT:

version = "1.0.1-SNAPSHOT"

Then run:

./gradlew publishCentralSnapshot

The plugin publishes to:

https://central.sonatype.com/repository/maven-snapshots/

Publish A Release To Maven Central

For a release version, do not use -SNAPSHOT:

version = "1.0.0"

Build the signed Central Portal zip:

./gradlew zipCentralPortalBundle

This command does three things:

  1. Creates the Maven publication.
  2. Signs all needed files with GPG.
  3. Creates a zip file for Central Portal.

The zip file is created in:

build/central-portal

Upload and publish the release:

./gradlew uploadCentralPortalBundle

This uploads the zip to Maven Central Portal with automatic publishing.

Useful Tasks

./gradlew publishToMavenLocal

Publish to your local Maven cache.

./gradlew publishAllPublicationsToLocalReleaseRepository

Publish to build/repo.

./gradlew publishCentralSnapshot

Publish a -SNAPSHOT version.

./gradlew zipCentralPortalBundle

Create a signed release zip for Central Portal.

./gradlew uploadCentralPortalBundle

Upload the release zip to Maven Central Portal.

Full Client Example

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.android")
    id("io.github.auxdk.publish") version "0.1.2"
}

group = "io.github.myname"
version = "1.0.0"

android {
    namespace = "io.github.myname.mylibrary"
    compileSdk = 36

    defaultConfig {
        minSdk = 23
    }
}

mavenCentralPublishing {
    pomName.set("My Library")
    pomDescription.set("A small Android library.")
    pomUrl.set("https://github.com/myname/my-library")

    licenseName.set("The Apache License, Version 2.0")
    licenseUrl.set("https://www.apache.org/licenses/LICENSE-2.0.txt")

    developerId.set("myname")
    developerName.set("My Name")
    developerEmail.set("me@example.com")

    scmConnection.set("scm:git:https://github.com/myname/my-library.git")
    scmDeveloperConnection.set("scm:git:ssh://git@github.com/myname/my-library.git")
    scmUrl.set("https://github.com/myname/my-library")
}

Custom Coordinates

By default, the plugin uses:

  • group from the Gradle project
  • project.name as artifact id
  • version from the Gradle project

You can override them:

mavenCentralPublishing {
    groupId.set("io.github.myname")
    artifactId.set("my-library")
    version.set("1.0.0")
}

Notes

Use a new version for every release. Maven Central does not allow replacing an old release version.

Keep local.properties private. It can contain tokens and signing data.

If upload fails, open Maven Central Portal and check the deployment status. The portal can show extra validation errors.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages