Skip to content

Commit

Permalink
Publish to Maven package to Maven Central instead of GitHub Registry (#…
Browse files Browse the repository at this point in the history
…17)

* Publish to Maven package to Maven Central instead of GitHub Registry

* Only apply archive.gradle when we publish the package
  • Loading branch information
supl authored Nov 20, 2023
1 parent bc38fff commit 8448da7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions lib/archive.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

publishing {
publications {
Expand Down Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

0 comments on commit 8448da7

Please sign in to comment.