diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 53201dd02..69974aa23 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,20 +32,20 @@ jobs: java-version: '17' distribution: 'temurin' - uses: gradle/actions/wrapper-validation@v4 - - name: Create .gpg key + - name: Set up Gradle Publishing Environment Variables run: | echo $GPG_KEY_ARMOR | base64 --decode > ./release.asc gpg --quiet --output $GITHUB_WORKSPACE/release.gpg --dearmor ./release.asc echo "Build and publish" - sed -i -e "s,sonatypeToken=,sonatypeToken=$SONATYPE_TOKEN_USERNAME,g" gradle.properties + sed -i -e "s,mavenCentralUsername=,mavenCentralUsername=$SONATYPE_TOKEN_USERNAME,g" gradle.properties SONATYPE_TOKEN_PASSWORD_ESCAPED=$(printf '%s\n' "$SONATYPE_TOKEN_PASSWORD" | sed -e 's/[\/&]/\\&/g') - sed -i -e "s,sonatypeTokenPassword=,sonatypeTokenPassword=$SONATYPE_TOKEN_PASSWORD_ESCAPED,g" gradle.properties + sed -i -e "s,mavenCentralPassword=,mavenCentralPassword=$SONATYPE_TOKEN_PASSWORD_ESCAPED,g" gradle.properties sed -i -e "s,signing.keyId=,signing.keyId=$GPG_KEY_ID,g" gradle.properties sed -i -e "s,signing.password=,signing.password=$GPG_PASSWORD,g" gradle.properties sed -i -e "s,signing.secretKeyRingFile=,signing.secretKeyRingFile=$GITHUB_WORKSPACE/release.gpg,g" gradle.properties env: - GPG_KEY_ARMOR: "${{ secrets.SYNCED_GPG_KEY_ARMOR }}" + GPG_KEY_ARMOR: ${{ secrets.SYNCED_GPG_KEY_ARMOR }} GPG_KEY_ID: ${{ secrets.SYNCED_GPG_KEY_ID }} GPG_PASSWORD: ${{ secrets.SYNCED_GPG_KEY_PASSWORD }} SONATYPE_TOKEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN_PASSWORD }} diff --git a/.releaserc b/.releaserc index 58210c177..5453d844b 100644 --- a/.releaserc +++ b/.releaserc @@ -20,7 +20,7 @@ plugins: to: ":${nextRelease.version}" - - "@semantic-release/exec" - prepareCmd: "./gradlew build --warn --stacktrace" - publishCmd: "./gradlew publish --warn --stacktrace --debug --info" + publishCmd: "./gradlew publishToMavenCentral --warn --stacktrace --debug --info" - - "@semantic-release/git" - assets: - "build.gradle.kts" diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 0525b582a..e1fc0f723 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -30,6 +30,7 @@ dependencies { implementation(libs.gradle) implementation(libs.dokka.gradle.plugin) implementation(libs.org.jacoco.core) + implementation(libs.gradle.maven.publish.plugin) } gradlePlugin { diff --git a/build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt b/build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt index 7a8055372..a476a1584 100644 --- a/build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Google LLC + * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,40 +15,34 @@ */ // buildSrc/src/main/kotlin/PublishingConventionPlugin.kt +import com.vanniktech.maven.publish.AndroidSingleVariantLibrary +import com.vanniktech.maven.publish.MavenPublishBaseExtension import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication import org.gradle.kotlin.dsl.* import org.gradle.testing.jacoco.plugins.JacocoPluginExtension import org.gradle.api.tasks.testing.Test import org.gradle.testing.jacoco.plugins.JacocoTaskExtension -import org.gradle.plugins.signing.SigningExtension -import org.gradle.api.publish.maven.* class PublishingConventionPlugin : Plugin { override fun apply(project: Project) { project.run { - applyPlugins() configureJacoco() - configurePublishing() - configureSigning() + configureVanniktechPublishing() } } private fun Project.applyPlugins() { apply(plugin = "com.android.library") apply(plugin = "com.mxalbert.gradle.jacoco-android") - apply(plugin = "maven-publish") apply(plugin = "org.jetbrains.dokka") - apply(plugin = "signing") + apply(plugin = "com.vanniktech.maven.publish") } private fun Project.configureJacoco() { configure { toolVersion = "0.8.7" - } tasks.withType().configureEach { @@ -59,76 +53,46 @@ class PublishingConventionPlugin : Plugin { } } - private fun Project.configurePublishing() { - extensions.configure { - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } - } - extensions.configure { - publications { - create("aar") { - artifactId = if (project.name == "library") { - "android-maps-utils" - } else { - null - } + private fun Project.configureVanniktechPublishing() { + extensions.configure { + configure( + AndroidSingleVariantLibrary( + variant = "release", + sourcesJar = true, + publishJavadocJar = true + ) + ) - afterEvaluate { - from(components["release"]) - } - pom { - name.set(project.name) - description.set("Handy extensions to the Google Maps Android API.") - url.set("https://github.com/googlemaps/android-maps-utils") - scm { - connection.set("scm:git@github.com:googlemaps/android-maps-utils.git") - developerConnection.set("scm:git@github.com:googlemaps/android-maps-utils.git") - url.set("scm:git@github.com:googlemaps/android-maps-utils.git") - } - licenses { - license { - name.set("The Apache Software License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - distribution.set("repo") - } - } - organization { - name.set("Google Inc") - url.set("http://developers.google.com/maps") - } - developers { - developer { - name.set("Google Inc.") - } - } + publishToMavenCentral() + signAllPublications() + + pom { + name.set(project.name) + description.set("Handy extensions to the Google Maps Android API.") + url.set("https://github.com/googlemaps/android-maps-utils") + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") } } - } - repositories { - maven { - val releasesRepoUrl = - uri("https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/") - val snapshotsRepoUrl = - uri("https://central.sonatype.com/repository/maven-snapshots/") - url = if (project.version.toString() - .endsWith("SNAPSHOT") - ) snapshotsRepoUrl else releasesRepoUrl - credentials { - username = project.findProperty("sonatypeToken") as String? - password = project.findProperty("sonatypeTokenPassword") as String? + scm { + connection.set("scm:git@github.com:googlemaps/android-maps-utils.git") + developerConnection.set("scm:git@github.com:googlemaps/android-maps-utils.git") + url.set("https://github.com/googlemaps/android-maps-utils") + } + developers { + developer { + id.set("google") + name.set("Google Inc.") } } + organization { + name.set("Google Inc") + url.set("http://developers.google.com/maps") + } } } } - - private fun Project.configureSigning() { - configure { - sign(extensions.getByType().publications["aar"]) - } - } } diff --git a/gradle.properties b/gradle.properties index 247dde2dd..c0f003139 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,11 @@ signing.keyId= signing.password= signing.secretKeyRingFile= -sonatypeToken= -sonatypeTokenPassword= - android.defaults.buildfeatures.buildconfig=true + +mavenCentralUsername= +mavenCentralPassword= + +# Add a property to enable automatic release to Maven Central (optional, but good for CI) +# If true, publishToMavenCentral will also close and release the staging repository +mavenCentralAutomaticRelease=false \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6ca9336a6..862036287 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,6 +19,7 @@ mockk = "1.14.4" lint = "31.11.0" org-jacoco-core = "0.8.13" material = "1.12.0" +gradleMavenPublishPlugin = "0.34.0" [libraries] appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" } @@ -47,4 +48,5 @@ lint = { module = "com.android.tools.lint:lint", version.ref = "lint" } lint-tests = { module = "com.android.tools.lint:lint-tests", version.ref = "lint" } testutils = { module = "com.android.tools:testutils", version.ref = "lint" } org-jacoco-core = { module = "org.jacoco:org.jacoco.core", version.ref = "org-jacoco-core" } -material = { group = "com.google.android.material", name = "material", version.ref = "material" } \ No newline at end of file +material = { group = "com.google.android.material", name = "material", version.ref = "material" } +gradle-maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradleMavenPublishPlugin" } \ No newline at end of file