From 31131c921c0a1699e8b790323152224913cdf73c Mon Sep 17 00:00:00 2001 From: Brandon Estrella Date: Thu, 11 Jun 2026 10:32:52 -0700 Subject: [PATCH] build: publish to Maven Central via the Central Portal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sonatype sunset the legacy OSSRH endpoint (s01.oss.sonatype.org) that the previous publishing config targeted. Replace the manual maven-publish + signing setup with the com.vanniktech.maven.publish plugin pointed at the Central Portal (SonatypeHost.CENTRAL_PORTAL). - Coordinates and POM metadata are still read from gradle.properties (GROUP / POM_ARTIFACT_ID / VERSION_NAME / POM_*), which already use the plugin's conventions — no pom block needed. - Adds the required sources + javadoc (Dokka) jars automatically. - Credentials and signing key come from ~/.gradle/gradle.properties (mavenCentralUsername/Password, signingInMemoryKey[/Password]); never committed. Verified locally: publish tasks resolve, signMavenPublication signs all artifacts, and the unit tests still pass. --- build.gradle.kts | 1 + gradle/libs.versions.toml | 2 + sdk/build.gradle.kts | 81 ++++++++++----------------------------- 3 files changed, 23 insertions(+), 61 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0cfe2cf..3b52faf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,4 +2,5 @@ plugins { alias(libs.plugins.android.library) apply false alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.ksp) apply false + alias(libs.plugins.maven.publish.vanniktech) apply false } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3c4b8e3..6dcf8d4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ moshi = "1.15.1" coroutines = "1.8.0" junit5 = "5.10.2" mockk = "1.13.10" +mavenPublish = "0.30.0" [libraries] okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" } @@ -24,3 +25,4 @@ mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" } android-library = { id = "com.android.library", version.ref = "agp" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +maven-publish-vanniktech = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } diff --git a/sdk/build.gradle.kts b/sdk/build.gradle.kts index 47aeaef..ec75c3c 100644 --- a/sdk/build.gradle.kts +++ b/sdk/build.gradle.kts @@ -1,9 +1,11 @@ +import com.vanniktech.maven.publish.AndroidSingleVariantLibrary +import com.vanniktech.maven.publish.SonatypeHost + plugins { alias(libs.plugins.android.library) alias(libs.plugins.kotlin.android) alias(libs.plugins.ksp) - `maven-publish` - signing + alias(libs.plugins.maven.publish.vanniktech) } android { @@ -69,63 +71,20 @@ dependencies { testImplementation(libs.okhttp.mockwebserver) } -// Maven Central publishing -publishing { - publications { - create("release") { - groupId = property("GROUP").toString() - artifactId = property("POM_ARTIFACT_ID").toString() - version = property("VERSION_NAME").toString() - - afterEvaluate { - from(components["release"]) - } - - pom { - name.set(property("POM_NAME").toString()) - description.set(property("POM_DESCRIPTION").toString()) - url.set(property("POM_URL").toString()) - - licenses { - license { - name.set(property("POM_LICENCE_NAME").toString()) - url.set(property("POM_LICENCE_URL").toString()) - } - } - - developers { - developer { - id.set(property("POM_DEVELOPER_ID").toString()) - name.set(property("POM_DEVELOPER_NAME").toString()) - url.set(property("POM_DEVELOPER_URL").toString()) - } - } - - scm { - url.set(property("POM_SCM_URL").toString()) - connection.set(property("POM_SCM_CONNECTION").toString()) - developerConnection.set(property("POM_SCM_DEV_CONNECTION").toString()) - } - } - } - } - - repositories { - maven { - name = "sonatype" - val releasesUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") - val snapshotsUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") - url = if (version.toString().endsWith("SNAPSHOT")) snapshotsUrl else releasesUrl - - credentials { - username = findProperty("ossrhUsername")?.toString() ?: System.getenv("OSSRH_USERNAME") - password = findProperty("ossrhPassword")?.toString() ?: System.getenv("OSSRH_PASSWORD") - } - } - } -} - -signing { - useGpgCmd() - sign(publishing.publications["release"]) +// Maven Central publishing via the Central Portal (central.sonatype.com). +// Coordinates (GROUP / POM_ARTIFACT_ID / VERSION_NAME) and POM metadata (POM_*) +// are read automatically from gradle.properties. Credentials and the signing key +// come from ~/.gradle/gradle.properties (mavenCentralUsername / mavenCentralPassword +// / signingInMemoryKey / signingInMemoryKeyPassword) — never committed. +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true) + signAllPublications() + + configure( + AndroidSingleVariantLibrary( + variant = "release", + sourcesJar = true, + publishJavadocJar = true, + ) + ) }