From 8448da72bbf232f8f202b0d660264235ea7c6a20 Mon Sep 17 00:00:00 2001 From: Plenty Su Date: Mon, 20 Nov 2023 18:02:25 +0900 Subject: [PATCH] Publish to Maven package to Maven Central instead of GitHub Registry (#17) * Publish to Maven package to Maven Central instead of GitHub Registry * Only apply archive.gradle when we publish the package --- .github/workflows/release.yml | 10 +++++++--- lib/archive.gradle | 13 ++++++++++--- lib/build.gradle | 7 ++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0a6b1ba..3d73a37 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,12 +34,16 @@ jobs: echo "version=${VERSION}" >> $GITHUB_OUTPUT - - name: Upload the package to GitHub Package + - name: Upload the package to Maven Central Repository run: | + echo "${{ secrets.SIGNING_SECRET_KEY_RING }}" | base64 -d > ~/.gradle/secring.gpg ./gradlew publish \ -PprojVersion="${{ steps.version.outputs.version }}" \ - -PgprUsername="${{ github.repository_owner }}" \ - -PgprPassword="${{ secrets.CR_PAT }}" + -Psigning.keyId="${{ secrets.SIGNING_KEY_ID }}" \ + -Psigning.password="${{ secrets.SIGNING_PASSWORD }}" \ + -Psigning.secretKeyRingFile="$(echo ~/.gradle/secring.gpg)" \ + -PossrhUsername="${{ secrets.OSSRH_USERNAMAE }}" \ + -PossrhPassword="${{ secrets.OSSRH_PASSWORD }}" - name: Build the shadow Jar run: ./gradlew shadowJar diff --git a/lib/archive.gradle b/lib/archive.gradle index 70722bc..6d7b268 100644 --- a/lib/archive.gradle +++ b/lib/archive.gradle @@ -1,4 +1,5 @@ apply plugin: 'maven-publish' +apply plugin: 'signing' publishing { publications { @@ -37,11 +38,17 @@ publishing { } repositories { maven { - url = uri("https://maven.pkg.github.com/scalar-labs/scalar-admin-k8s") + def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" + def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots" + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl credentials { - username = project.findProperty("gprUsername") ?: System.getenv("GPR_USERNAME") - password = project.findProperty("gprPassword") ?: System.getenv("GPR_PASSWORD") + username = "${ossrhUsername}" + password = "${ossrhPassword}" } } } } + +signing { + sign publishing.publications.mavenJava +} diff --git a/lib/build.gradle b/lib/build.gradle index 14a2163..0d956d4 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -17,4 +17,9 @@ test { } } -apply from: 'archive.gradle' +// for archiving and uploading to maven central +if (!project.gradle.startParameter.taskNames.isEmpty() && + (project.gradle.startParameter.taskNames[0].endsWith('publish') || + project.gradle.startParameter.taskNames[0].endsWith('publishToMavenLocal'))) { + apply from: 'archive.gradle' +}