diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8b77ede..f435015 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,28 +16,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: adopt java-version: 11 - # Builds the release artifacts of the library - - name: Release build - run: ./gradlew :espresso:assembleRelease - - # Generates other artifacts (javadocJar is optional) - - name: Source jar and dokka - run: ./gradlew androidSourcesJar - - # Runs upload, and then closes & releases the repository - - name: Publish to MavenCentral - run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository + # Builds + signs the release AAR (with sources/javadoc jars), uploads + # to the Sonatype Central Portal, and auto-releases the deployment. + - name: Publish to Maven Central + run: ./gradlew publishToMavenCentral --max-workers 1 --no-configuration-cache env: - OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} - OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} - SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} - SIGNING_KEY: ${{ secrets.SIGNING_KEY }} - SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} diff --git a/build.gradle b/build.gradle index caec2ba..c24113e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,5 @@ plugins { id 'com.android.application' version '7.4.1' apply false id 'com.android.library' version '7.4.1' apply false - id("io.github.gradle-nexus.publish-plugin") version "1.1.0" + id 'com.vanniktech.maven.publish' version '0.30.0' apply false } -apply from: "${rootDir}/scripts/publish-root.gradle" diff --git a/espresso/build.gradle b/espresso/build.gradle index 2687df7..6edef11 100644 --- a/espresso/build.gradle +++ b/espresso/build.gradle @@ -1,5 +1,8 @@ +import com.vanniktech.maven.publish.AndroidSingleVariantLibrary + plugins { id 'com.android.library' + id 'com.vanniktech.maven.publish' } android { @@ -32,10 +35,37 @@ dependencies { implementation 'androidx.test:core:1.5.0' } -ext { - PUBLISH_GROUP_ID = 'io.percy' - PUBLISH_VERSION = '1.0.5-beta.0' - PUBLISH_ARTIFACT_ID = 'espresso-java' -} +mavenPublishing { + coordinates('io.percy', 'espresso-java', '1.0.5-beta.0') + + // Publish the release AAR with sources + javadoc jars (javadoc jar is + // required by Maven Central release validation). + configure(new AndroidSingleVariantLibrary('release', true, true)) -apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" + // Central Portal is the default host; `true` auto-releases the deployment + // after upload (replaces the old close-and-release Nexus step). + publishToMavenCentral(true) + signAllPublications() + + pom { + name = 'espresso-java' + description = 'App Percy official espresso SDK' + url = 'https://github.com/percy/percy-espresso-java' + licenses { + license { + name = 'MIT License' + url = 'https://github.com/percy/percy-espresso-java/blob/main/LICENSE' + } + } + developers { + developer { + name = 'Team Browserstack' + } + } + scm { + connection = 'scm:git:github.com/percy/percy-espresso-java.git' + developerConnection = 'scm:git:ssh://github.com/percy/percy-espresso-java.git' + url = 'https://github.com/percy/percy-espresso-java/tree/main' + } + } +} diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle deleted file mode 100644 index 26046c0..0000000 --- a/scripts/publish-module.gradle +++ /dev/null @@ -1,73 +0,0 @@ -apply plugin: 'maven-publish' -apply plugin: 'signing' - -task androidSourcesJar(type: Jar) { - archiveClassifier.set('sources') - if (project.plugins.findPlugin("com.android.library")) { - // For Android libraries - from android.sourceSets.main.java.srcDirs - from android.sourceSets.main.kotlin.srcDirs - } else { - from sourceSets.main.java.srcDirs - from sourceSets.main.kotlin.srcDirs - } -} -artifacts { - archives androidSourcesJar -} - -afterEvaluate { - publishing { - publications { - release(MavenPublication) { - // The coordinates of the library, being set from variables that - // we'll set up later - groupId PUBLISH_GROUP_ID - artifactId PUBLISH_ARTIFACT_ID - version PUBLISH_VERSION - - // Two artifacts, the `aar` (or `jar`) and the sources - if (project.plugins.findPlugin("com.android.library")) { - from components.release - } else { - from components.java - } - - artifact androidSourcesJar - - // Mostly self-explanatory metadata - pom { - name = PUBLISH_ARTIFACT_ID - description = 'App Percy official espresso SDK' - url = 'https://github.com/percy/percy-espresso-java' - licenses { - license { - name = 'MIT License' - url = 'https://github.com/percy/percy-espresso-java/blob/main/LICENSE' - } - } - developers { - developer { - name = 'Team Browserstack' - } - } - - scm { - connection = 'scm:git:github.com/percy/percy-espresso-java.git' - developerConnection = 'scm:git:ssh://github.com/percy/percy-espresso-java.git' - url = 'https://github.com/percy/percy-espresso-java/tree/main' - } - } - } - } - } -} - -signing { - useInMemoryPgpKeys( - rootProject.ext["signing.keyId"], - rootProject.ext["signing.key"], - rootProject.ext["signing.password"], - ) - sign publishing.publications -} diff --git a/scripts/publish-root.gradle b/scripts/publish-root.gradle deleted file mode 100644 index c7e88b2..0000000 --- a/scripts/publish-root.gradle +++ /dev/null @@ -1,35 +0,0 @@ -// Create variables with empty default values -ext["signing.keyId"] = '' -ext["signing.password"] = '' -ext["signing.key"] = '' -ext["ossrhUsername"] = '' -ext["ossrhPassword"] = '' -ext["sonatypeStagingProfileId"] = '' - -File secretPropsFile = project.rootProject.file('local.properties') -if (secretPropsFile.exists()) { - // Read local.properties file first if it exists - Properties p = new Properties() - new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } - p.each { name, value -> ext[name] = value } -} else { - // Use system environment variables - ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') - ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') - ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') - ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') - ext["signing.password"] = System.getenv('SIGNING_PASSWORD') - ext["signing.key"] = System.getenv('SIGNING_KEY') -} - -nexusPublishing { - repositories { - sonatype { - stagingProfileId = sonatypeStagingProfileId - username = ossrhUsername - password = ossrhPassword - nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/")) - } - } -}