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"The plugin configures these parts for you:
maven-publish- Android
releasepublication - 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.
The plugin currently declares Configuration Cache as not supported. Its publishing tasks run local GPG signing and Maven Central Portal upload steps.
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
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")
}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_IDYou 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 that GPG works:
gpg --list-secret-keys --keyid-format LONGYou 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-signIf you set signingKeyId, the plugin also uses:
--local-user YOUR_GPG_KEY_IDPublish to your local Maven cache:
./gradlew publishToMavenLocalThis is good for a quick test in another local project.
You can also publish to a local folder:
./gradlew publishAllPublicationsToLocalReleaseRepositoryThe files are created in:
build/repo
For a snapshot version, your version must end with -SNAPSHOT:
version = "1.0.1-SNAPSHOT"Then run:
./gradlew publishCentralSnapshotThe plugin publishes to:
https://central.sonatype.com/repository/maven-snapshots/
For a release version, do not use -SNAPSHOT:
version = "1.0.0"Build the signed Central Portal zip:
./gradlew zipCentralPortalBundleThis command does three things:
- Creates the Maven publication.
- Signs all needed files with GPG.
- Creates a zip file for Central Portal.
The zip file is created in:
build/central-portal
Upload and publish the release:
./gradlew uploadCentralPortalBundleThis uploads the zip to Maven Central Portal with automatic publishing.
./gradlew publishToMavenLocalPublish to your local Maven cache.
./gradlew publishAllPublicationsToLocalReleaseRepositoryPublish to build/repo.
./gradlew publishCentralSnapshotPublish a -SNAPSHOT version.
./gradlew zipCentralPortalBundleCreate a signed release zip for Central Portal.
./gradlew uploadCentralPortalBundleUpload the release zip to Maven Central Portal.
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")
}By default, the plugin uses:
groupfrom the Gradle projectproject.nameas artifact idversionfrom the Gradle project
You can override them:
mavenCentralPublishing {
groupId.set("io.github.myname")
artifactId.set("my-library")
version.set("1.0.0")
}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.