Skip to content

Commit 65e6fb5

Browse files
Use JReleaser to publish to new Maven Central API
Publishing to Maven Central using OSSRH is deprecated and is sunset on 2025-06-30. The build needs to be migrated to use the Central Publishing Portal. There is currently no support for this in Gradle's own publishing capability, and no official Sonatype Gradle publishing plugin. JReleaser is currently recommended by Sonatype for Gradle publishing to Maven Central. Signed-off-by: Mark S. Lewis <[email protected]>
1 parent fd50d8a commit 65e6fb5

File tree

2 files changed

+106
-81
lines changed

2 files changed

+106
-81
lines changed

.github/workflows/release.yml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ env:
1515
IMAGE_NAME: ${{ github.repository_owner }}/fabric-javaenv
1616

1717
jobs:
18-
# Publishing steps to both the Github Packages and the Sonatype
19-
publishjars:
20-
strategy:
21-
fail-fast: false
22-
matrix:
23-
publish_target:
24-
- publishAllPublicationsToGithubPackagesRepository
25-
- publishAllPublicationsToReleaseRepository
18+
publish-github:
2619
runs-on: ubuntu-latest
2720
permissions:
2821
contents: read
@@ -34,18 +27,37 @@ jobs:
3427
distribution: "temurin"
3528
java-version: 21
3629
- uses: gradle/actions/setup-gradle@v4
37-
- name: Push to registry ${{ matrix.publish_target }}
30+
- name: Publish to GitHub Packages
3831
run: |
39-
set -xev
40-
./gradlew -Psigning.key="${SIGNING_KEY}" -Psigning.password="${SIGNING_PASSWORD}" -PossrhUsername="${OSSRH_USER}" -PossrhPassword="${OSSRH_PASSWORD}" ${TARGET}
32+
./gradlew -Psigning.key="${SIGNING_KEY}" -Psigning.password="${SIGNING_PASSWORD}" publishAllPublicationsToGitHubRepository
4133
env:
4234
SIGNING_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
4335
SIGNING_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
44-
OSSRH_USER: ${{ secrets.OSSRH_USERNAME }}
45-
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
46-
TARGET: ${{ matrix.publish_target }}
4736
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4837

38+
publish-maven:
39+
runs-on: ubuntu-latest
40+
permissions:
41+
contents: read
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: actions/setup-java@v4
45+
with:
46+
distribution: "temurin"
47+
java-version: 21
48+
- uses: gradle/actions/setup-gradle@v4
49+
- name: Publish to local staging
50+
run: |
51+
./gradlew publishAllPublicationsToStagingRepository
52+
- name: Publish to Maven Central
53+
run: |
54+
./gradlew jreleaserDeploy --stacktrace
55+
env:
56+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
57+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
58+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVENCENTRAL_USERNAME }}
59+
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVENCENTRAL_PASSWORD }}
60+
4961
docker-build-push:
5062
name: Push Docker image
5163
runs-on: ${{ matrix.arch.runner }}

fabric-chaincode-shim/build.gradle

Lines changed: 80 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
plugins {
88
id 'maven-publish'
9-
id 'jacoco'
109
id 'signing'
10+
id 'org.jreleaser' version '1.18.0'
11+
id 'jacoco'
1112
id 'pmd'
1213
}
1314

@@ -137,7 +138,7 @@ jacocoTestCoverageVerification {
137138
test.finalizedBy(jacocoTestReport)
138139
test.finalizedBy(jacocoTestCoverageVerification)
139140

140-
task licenseCheck {
141+
tasks.register('licenseCheck') {
141142
group = "license"
142143
description = "Checks the License part of each source file"
143144

@@ -146,29 +147,32 @@ task licenseCheck {
146147
def missing = new LinkedList<File>()
147148
sourceSets.forEach {
148149
sourceSet ->
149-
sourceSet.allSource.findAll { !it.path.contains("build") && !(it.path.contains("test") && it.path.contains("resources"))}.each {
150+
sourceSet.allSource.findAll {
151+
!it.path.contains("build") &&
152+
!(it.path.contains("test") && it.path.contains("resources"))
153+
}.each {
150154
file ->
151-
if (!file.name.contains("json")){
152-
BufferedReader r = new BufferedReader(new FileReader(file))
153-
def line, hasSPDX = false, hasTraditional = false
154-
while ((line = r.readLine()) != null) {
155-
if (line.contains("SPDX-License-Identifier")) {
156-
hasSPDX = true
157-
break
155+
if (!file.name.contains("json")) {
156+
BufferedReader r = new BufferedReader(new FileReader(file))
157+
def line, hasSPDX = false, hasTraditional = false
158+
while ((line = r.readLine()) != null) {
159+
if (line.contains("SPDX-License-Identifier")) {
160+
hasSPDX = true
161+
break
162+
}
163+
if (line.contains("http://www.apache.org/licenses/LICENSE-2.0")) {
164+
hasTraditional = true
165+
break
166+
}
158167
}
159-
if (line.contains("http://www.apache.org/licenses/LICENSE-2.0")) {
160-
hasTraditional = true
161-
break
162-
}
163-
}
164-
if (!hasSPDX) {
165-
if (hasTraditional) {
166-
noSPDX.add(file)
167-
} else {
168-
missing.add(file)
168+
if (!hasSPDX) {
169+
if (hasTraditional) {
170+
noSPDX.add(file)
171+
} else {
172+
missing.add(file)
173+
}
169174
}
170175
}
171-
}
172176
}
173177
}
174178

@@ -212,18 +216,12 @@ javadoc {
212216

213217
classpath = sourceSets.main.runtimeClasspath
214218

215-
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
219+
options.addStringOption('Xdoclint:none', '-quiet')
220+
options.addStringOption('Xwerror', '-quiet')
216221
options.overview = "src/main/java/org/hyperledger/fabric/overview.html"
217-
}
218222

219-
if (JavaVersion.current().isJava8Compatible()) {
220-
project.tasks.withType(Javadoc) {
221-
options.addStringOption('Xdoclint:all', '-quiet')
222-
options.addStringOption('Xwerror', '-quiet')
223-
}
224223
}
225224

226-
227225
publishing {
228226
publications {
229227
shim(MavenPublication) {
@@ -235,10 +233,12 @@ publishing {
235233
name = 'JavaChaincodeShim'
236234
packaging = 'jar'
237235
description = 'Hyperledger Fabric Java Chaincode Shim'
238-
url = 'http://www.hyperledger.org/'
236+
url = 'https://hyperledger.github.io/fabric-chaincode-java/'
239237

240238
scm {
241-
url = 'https://github.com/hyperledger/fabric-chaincode-java.git'
239+
connection = 'scm:git:https://github.com/hyperledger/fabric-chaincode-java.git'
240+
developerConnection = 'scm:git:ssh://github.com:hyperledger/fabric-chaincode-java.git'
241+
url = 'https://github.com/hyperledger/fabric-chaincode-java'
242242
}
243243
licenses {
244244
license {
@@ -248,26 +248,16 @@ publishing {
248248
}
249249

250250
developers {
251-
developer {
252-
id = 'gennadylaventman'
253-
name = 'Gennady Laventman'
254-
255-
}
256-
developer {
257-
id = 'luiss'
258-
name = 'Luis Sanchez'
259-
260-
}
261-
developer {
262-
id = 'C0rWin'
263-
name = 'Artem Barger'
264-
265-
}
266251
developer {
267252
id = 'denyeart'
268253
name = 'David Enyeart'
269254
270255
}
256+
developer {
257+
id = 'bestbeforetoday'
258+
name = 'Mark S. Lewis'
259+
260+
}
271261
}
272262
}
273263
}
@@ -276,17 +266,12 @@ publishing {
276266

277267
repositories {
278268
maven {
279-
name = "release"
280-
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
281-
credentials {
282-
username = project.findProperty('ossrhUsername')
283-
password = project.findProperty('ossrhPassword')
284-
}
285-
269+
name = "Staging"
270+
url = layout.buildDirectory.dir('staging-deploy')
286271
}
287272

288273
maven {
289-
name = "GitHubPackages"
274+
name = "GitHub"
290275
url = "https://maven.pkg.github.com/hyperledger/fabric-chaincode-java"
291276
credentials {
292277
username = System.getenv("GITHUB_ACTOR")
@@ -310,12 +295,39 @@ signing {
310295
}
311296
}
312297

298+
jreleaser {
299+
gitRootSearch = true
300+
signing {
301+
active = 'ALWAYS'
302+
armored = true
303+
verify = false
304+
}
305+
deploy {
306+
maven {
307+
mavenCentral {
308+
sonatype {
309+
active = 'ALWAYS'
310+
url = 'https://central.sonatype.com/api/v1/publisher'
311+
stagingRepository(layout.buildDirectory.dir('staging-deploy').get().toString())
312+
}
313+
}
314+
}
315+
}
316+
release {
317+
github {
318+
skipRelease = true
319+
skipTag = true
320+
token = 'EMPTY'
321+
}
322+
}
323+
}
324+
313325
// Need to specify the sourcesJar task BEFORE the java{withSourcesJar()} so that it picks up the duplicatesStratergy
314326
// otherwise this fails with a duplicates error.
315327
// (see https://github.com/gradle/gradle/issues/17236)
316328

317-
task sourcesJar(type: Jar) {
318-
duplicatesStrategy = 'include'
329+
tasks.register('sourcesJar', Jar) {
330+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
319331
archiveClassifier = 'sources'
320332
from sourceSets.main.allSource
321333
}
@@ -332,16 +344,16 @@ build.dependsOn licenseCheck
332344
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
333345
import org.gradle.api.tasks.testing.logging.TestLogEvent
334346

335-
tasks.withType(Test) {
347+
tasks.withType(Test).configureEach {
336348

337349
environment "CORE_PEER_LOCALMSPID", "mymsp"
338350

339351
testLogging {
340352
// set options for log level LIFECYCLE
341353
events TestLogEvent.FAILED,
342-
TestLogEvent.PASSED,
343-
TestLogEvent.SKIPPED,
344-
TestLogEvent.STANDARD_OUT
354+
TestLogEvent.PASSED,
355+
TestLogEvent.SKIPPED,
356+
TestLogEvent.STANDARD_OUT
345357
exceptionFormat = TestExceptionFormat.FULL
346358
showExceptions = true
347359
showCauses = true
@@ -350,22 +362,23 @@ tasks.withType(Test) {
350362
// set options for log level DEBUG and INFO
351363
debug {
352364
events TestLogEvent.STARTED,
353-
TestLogEvent.FAILED,
354-
TestLogEvent.PASSED,
355-
TestLogEvent.SKIPPED,
356-
TestLogEvent.STANDARD_ERROR,
357-
TestLogEvent.STANDARD_OUT
365+
TestLogEvent.FAILED,
366+
TestLogEvent.PASSED,
367+
TestLogEvent.SKIPPED,
368+
TestLogEvent.STANDARD_ERROR,
369+
TestLogEvent.STANDARD_OUT
358370
exceptionFormat = TestExceptionFormat.FULL
359371
}
360372
info.events = debug.events
361373
info.exceptionFormat = debug.exceptionFormat
362374

363-
afterSuite { desc, result ->
375+
afterSuite {desc, result ->
364376
if (!desc.parent) { // will match the outermost suite
365377
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
366378
def startItem = '| ', endItem = ' |'
367379
def repeatLength = startItem.length() + output.length() + endItem.length()
368-
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
380+
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' +
381+
('-' * repeatLength))
369382
}
370383
}
371384
}

0 commit comments

Comments
 (0)