Skip to content

Commit 7fefeee

Browse files
authored
chore: jreleaser for publishing to maven central portal (#120)
* jreleaser for publishing to maven central portal
1 parent 557c39b commit 7fefeee

File tree

3 files changed

+92
-31
lines changed

3 files changed

+92
-31
lines changed

.github/workflows/publish-sdk.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,39 @@ on:
55
types: [published]
66

77
env:
8-
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.OSSRH_USERNAME }}
9-
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }}
108
CI: true
119

1210
jobs:
1311
publish:
1412
runs-on: ubuntu-latest
13+
env:
14+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_TOKEN_USERNAME }}
15+
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_TOKEN_PASSWORD }}
16+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
17+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
18+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
19+
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1520
steps:
1621
- uses: actions/checkout@v4
1722
with:
1823
fetch-depth: 0
1924

20-
- name: Set up Maven Central Repository
25+
- name: Set up JDK 8
2126
uses: actions/setup-java@v4
2227
with:
2328
java-version: '8'
2429
distribution: 'temurin'
25-
server-id: ossrh
2630
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
2731
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
2832

2933
- name: Download test data
3034
run: make test-data
3135

32-
- name: Publish package to Maven Central
33-
run: ./gradlew check publish --no-daemon
34-
env:
35-
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
36-
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
36+
- name: Test
37+
run: ./gradlew check
38+
39+
- name: Stage artifacts
40+
run: ./gradlew clean publish -Prelease
41+
42+
- name: Deploy to Maven Central
43+
run: ./gradlew jreleaserDeploy

.github/workflows/publish-snapshot.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,41 @@ on:
55
branches: [main]
66

77
env:
8-
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.OSSRH_USERNAME }}
9-
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }}
108
CI: true
119

1210
jobs:
1311
publish-snapshot:
1412
runs-on: ubuntu-latest
13+
env:
14+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_TOKEN_USERNAME }}
15+
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_TOKEN_PASSWORD }}
16+
JRELEASER_NEXUS2_SNAPSHOT_DEPLOY_USERNAME: ${{ secrets.MAVEN_CENTRAL_TOKEN_USERNAME }}
17+
JRELEASER_NEXUS2_SNAPSHOT_DEPLOY_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN_PASSWORD }}
18+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
19+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
20+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
21+
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1522
steps:
1623
- uses: actions/checkout@v4
1724
with:
1825
fetch-depth: 0
1926

20-
- name: Set up JDK 17
27+
- name: Set up JDK 8
2128
uses: actions/setup-java@v4
2229
with:
2330
java-version: 17
2431
distribution: 'adopt'
2532
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
2633
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
2734

28-
- name: Publish Snapshot artifact
29-
run: make test-data && ./gradlew check publish --no-daemon --stacktrace
30-
env:
31-
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
32-
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
35+
- name: Download test data
36+
run: make test-data
37+
38+
- name: Test
39+
run: ./gradlew check
40+
41+
- name: Stage artifacts
42+
run: ./gradlew clean publish -Psnapshot
43+
44+
- name: Deploy to Maven Central
45+
run: ./gradlew jreleaserDeploy

build.gradle

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java-library'
33
id 'maven-publish'
4-
id 'signing'
4+
id 'org.jreleaser' version '1.18.0'
55
id "com.diffplug.spotless" version "6.13.0"
66
}
77

@@ -11,7 +11,7 @@ java {
1111
}
1212

1313
group = 'cloud.eppo'
14-
version = '5.2.1-SNAPSHOT'
14+
version = '5.2.1'
1515
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
1616

1717
import org.apache.tools.ant.filters.ReplaceTokens
@@ -86,7 +86,8 @@ java {
8686

8787
publishing {
8888
publications {
89-
mavenJava(MavenPublication) {
89+
maven(MavenPublication) {
90+
groupId = 'cloud.eppo'
9091
artifactId = 'eppo-server-sdk'
9192
from components.java
9293
versionMapping {
@@ -123,26 +124,66 @@ publishing {
123124
}
124125
repositories {
125126
maven {
126-
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
127-
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
128-
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
129-
credentials {
130-
username = project.properties.containsKey("ossrhUsername") ? project.properties["ossrhUsername"] : ""
131-
password = project.properties.containsKey("ossrhPassword") ? project.properties["ossrhPassword"] : ""
132-
}
127+
url = layout.buildDirectory.dir('staging-deploy')
133128
}
134129
}
135130
}
136131

137-
if (!project.gradle.startParameter.taskNames.contains('publishToMavenLocal')) {
132+
133+
jreleaser {
138134
signing {
139-
sign publishing.publications.mavenJava
140-
if (System.env['CI']) {
141-
useInMemoryPgpKeys(System.env.GPG_PRIVATE_KEY, System.env.GPG_PASSPHRASE)
135+
active = 'ALWAYS'
136+
armored = true
137+
verify = false
138+
}
139+
deploy {
140+
maven {
141+
mavenCentral {
142+
'release-deploy' {
143+
active = 'RELEASE'
144+
url = 'https://central.sonatype.com/api/v1/publisher'
145+
stagingRepository('build/staging-deploy')
146+
}
147+
}
148+
nexus2 {
149+
'snapshot-deploy' {
150+
active = 'SNAPSHOT'
151+
snapshotUrl = 'https://central.sonatype.com/repository/maven-snapshots'
152+
url = 'https://central.sonatype.com/repository/maven-snapshots'
153+
applyMavenCentralRules = true
154+
snapshotSupported = true
155+
closeRepository = true
156+
releaseRepository = true
157+
stagingRepository('build/staging-deploy')
158+
}
159+
}
142160
}
143161
}
144162
}
145163

164+
165+
// Custom task to ensure we can conditionally publish either a release or snapshot artifact
166+
// based on a command line switch. See github workflow files for more details on usage.
167+
tasks.register('checkVersion') {
168+
doLast {
169+
if (!project.hasProperty('release') && !project.hasProperty('snapshot')) {
170+
throw new GradleException("You must specify either -Prelease or -Psnapshot")
171+
}
172+
if (project.hasProperty('release') && project.version.endsWith('SNAPSHOT')) {
173+
throw new GradleException("You cannot specify -Prelease with a SNAPSHOT version")
174+
}
175+
if (project.hasProperty('snapshot') && !project.version.endsWith('SNAPSHOT')) {
176+
throw new GradleException("You cannot specify -Psnapshot with a non-SNAPSHOT version")
177+
}
178+
project.ext.shouldPublish = true
179+
}
180+
}
181+
182+
// Ensure checkVersion runs before publishing
183+
tasks.named('publish').configure {
184+
dependsOn checkVersion
185+
}
186+
146187
javadoc {
147188
if (JavaVersion.current().isJava9Compatible()) {
148189
options.addBooleanOption('html5', true)

0 commit comments

Comments
 (0)