Skip to content

Commit 5221568

Browse files
authored
Publish to Maven Central with JReleaser (#20)
1 parent 1f7bcd7 commit 5221568

3 files changed

Lines changed: 102 additions & 27 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v5
15+
with:
16+
fetch-depth: 0
17+
- uses: actions/setup-java@v5
18+
with:
19+
distribution: temurin
20+
java-version: '17'
21+
- uses: gradle/actions/setup-gradle@v5
22+
- name: Check that the tag matches the project version
23+
run: |
24+
version=$(./gradlew -q properties --property version | sed -n 's/^version: //p')
25+
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
26+
echo "Tag $GITHUB_REF_NAME does not match project version $version" >&2
27+
exit 1
28+
fi
29+
- name: Build and test
30+
run: ./gradlew build
31+
- name: Publish with JReleaser
32+
run: ./gradlew publishAllPublicationsToStagingRepository jreleaserFullRelease
33+
env:
34+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_SECRET_KEY }}
35+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_PUBLIC_KEY }}
36+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE }}
37+
JRELEASER_MAVENCENTRAL_SONATYPE_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
38+
JRELEASER_MAVENCENTRAL_SONATYPE_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
39+
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎build.gradle.kts‎

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import org.jreleaser.model.Active
2+
13
plugins {
24
id("java-library")
35
id("checkstyle")
4-
alias(libs.plugins.maven.publish)
6+
id("maven-publish")
7+
alias(libs.plugins.jreleaser)
58
}
69

710
group = "org.komamitsu"
@@ -12,6 +15,8 @@ java {
1215
toolchain {
1316
languageVersion = JavaLanguageVersion.of(17)
1417
}
18+
withJavadocJar()
19+
withSourcesJar()
1520
}
1621

1722
repositories {
@@ -31,7 +36,7 @@ dependencies {
3136
// PackageVersion.java carries the coordinates and version Jackson reports via Versioned.
3237
// Generate it from the Gradle project so it cannot drift from the published POM.
3338
val packageDir = "org/komamitsu/jackson/dataformat/msgpack"
34-
val generatePackageVersion by tasks.registering {
39+
val generatePackageVersion = tasks.register("generatePackageVersion") {
3540
val outputDir = layout.buildDirectory.dir("generated/sources/packageVersion/java/main")
3641
val projectVersion = project.version.toString()
3742
val projectGroup = project.group.toString()
@@ -128,32 +133,63 @@ checkstyle {
128133
maxWarnings = 0
129134
}
130135

131-
mavenPublishing {
132-
publishToMavenCentral()
133-
signAllPublications()
134-
135-
pom {
136-
name = project.name
137-
description = project.description
138-
url = "https://github.com/komamitsu/jackson-dataformat-msgpack"
139-
licenses {
140-
license {
141-
name = "Apache-2.0"
142-
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
136+
// Publications are staged locally; JReleaser signs them and uploads them to the Central Portal.
137+
val stagingDir = layout.buildDirectory.dir("staging-deploy")
138+
139+
publishing {
140+
publications {
141+
create<MavenPublication>("maven") {
142+
from(components["java"])
143+
144+
pom {
145+
name = project.name
146+
description = project.description
147+
url = "https://github.com/komamitsu/jackson-dataformat-msgpack"
148+
licenses {
149+
license {
150+
name = "Apache-2.0"
151+
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
152+
}
153+
}
154+
developers {
155+
developer {
156+
id = "komamitsu"
157+
name = "Mitsunori Komatsu"
158+
email = "komamitsu@gmail.com"
159+
url = "https://github.com/komamitsu"
160+
}
161+
}
162+
scm {
163+
url = "https://github.com/komamitsu/jackson-dataformat-msgpack"
164+
connection = "scm:git:git://github.com/komamitsu/jackson-dataformat-msgpack.git"
165+
developerConnection = "scm:git:ssh://git@github.com/komamitsu/jackson-dataformat-msgpack.git"
166+
}
143167
}
144168
}
145-
developers {
146-
developer {
147-
id = "komamitsu"
148-
name = "Mitsunori Komatsu"
149-
email = "komamitsu@gmail.com"
150-
url = "https://github.com/komamitsu"
151-
}
169+
}
170+
repositories {
171+
maven {
172+
name = "staging"
173+
url = uri(stagingDir)
152174
}
153-
scm {
154-
url = "https://github.com/komamitsu/jackson-dataformat-msgpack"
155-
connection = "scm:git:git://github.com/komamitsu/jackson-dataformat-msgpack.git"
156-
developerConnection = "scm:git:ssh://git@github.com/komamitsu/jackson-dataformat-msgpack.git"
175+
}
176+
}
177+
178+
jreleaser {
179+
signing {
180+
pgp {
181+
active = Active.ALWAYS
182+
armored = true
183+
}
184+
}
185+
deploy {
186+
maven {
187+
mavenCentral.create("sonatype") {
188+
active = Active.ALWAYS
189+
url = "https://central.sonatype.com/api/v1/publisher"
190+
applyMavenCentralRules = true
191+
stagingRepository(stagingDir.get().asFile.path)
192+
}
157193
}
158194
}
159195
}

‎gradle/libs.versions.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ hamcrest = "3.0"
66
commons-math3 = "3.6.1"
77
jmh = "1.37"
88
jmh-plugin = "0.7.3"
9-
maven-publish-plugin = "0.34.0"
9+
jreleaser = "1.26.0"
1010

1111
[libraries]
1212
jackson-databind = { module = "tools.jackson.core:jackson-databind", version.ref = "jackson" }
@@ -18,4 +18,4 @@ commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "co
1818

1919
[plugins]
2020
jmh = { id = "me.champeau.jmh", version.ref = "jmh-plugin" }
21-
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publish-plugin" }
21+
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser" }

0 commit comments

Comments
 (0)