Skip to content

Commit d4c16b9

Browse files
committed
Add github action to publish packages to the Maven Central
1 parent 9430b99 commit d4c16b9

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

.github/workflows/maven_publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish package to the Maven Central Repository
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Set up Java
13+
uses: actions/setup-java@v2
14+
with:
15+
java-version: '11'
16+
distribution: 'adopt'
17+
- name: Publish package
18+
run: ./gradlew -Prelease publishToSonatype closeAndReleaseSonatypeStagingRepository
19+
env:
20+
STAGING_PROFILE_ID : ${{ secrets.STAGING_PROFILE_ID }}
21+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
22+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
23+
ORG_GRADLE_PROJECT_signingKey : ${{ secrets.SIGNING_KEY }}
24+
ORG_GRADLE_PROJECT_signingPassword : ${{ secrets.SIGNING_PASSWORD }}

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ nexusPublishing {
1212
packageGroup = GROUP
1313
repositories {
1414
sonatype {
15-
stagingProfileId = project.hasProperty('mavenProfileId') ? "$mavenProfileId" : ''
16-
username = project.hasProperty('mavenCentralUsername') ? "$mavenCentralUsername" : ''
17-
password = project.hasProperty('mavenCentralPassword') ? "$mavenCentralPassword" : ''
15+
stagingProfileId = findProperty('mavenProfileId') ?: System.getenv("STAGING_PROFILE_ID")
16+
username = findProperty('mavenCentralUsername') ?: System.getenv("OSSRH_USERNAME")
17+
password = findProperty('mavenCentralPassword') ?: System.getenv("OSSRH_PASSWORD")
1818
}
1919
}
2020
}

unittest/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,10 @@ publishing {
8989

9090
signing {
9191
required rootProject.hasProperty('release')
92+
if (rootProject.hasProperty('signingKey')) {
93+
def signingKey = rootProject.findProperty("signingKey")
94+
def signingPassword = rootProject.findProperty("signingPassword")
95+
useInMemoryPgpKeys(signingKey, signingPassword)
96+
}
9297
sign publishing.publications.mavenJava
9398
}

0 commit comments

Comments
 (0)