Skip to content

Commit 2648a7d

Browse files
Use JReleaser to publish to new Maven Central API
Signed-off-by: Mark S. Lewis <[email protected]>
1 parent fd50d8a commit 2648a7d

File tree

2 files changed

+102
-92
lines changed

2 files changed

+102
-92
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: 76 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
plugins {
88
id 'maven-publish'
9+
id 'org.jreleaser' version '1.18.0'
910
id 'jacoco'
10-
id 'signing'
1111
id 'pmd'
1212
}
1313

@@ -137,7 +137,7 @@ jacocoTestCoverageVerification {
137137
test.finalizedBy(jacocoTestReport)
138138
test.finalizedBy(jacocoTestCoverageVerification)
139139

140-
task licenseCheck {
140+
tasks.register('licenseCheck') {
141141
group = "license"
142142
description = "Checks the License part of each source file"
143143

@@ -146,29 +146,32 @@ task licenseCheck {
146146
def missing = new LinkedList<File>()
147147
sourceSets.forEach {
148148
sourceSet ->
149-
sourceSet.allSource.findAll { !it.path.contains("build") && !(it.path.contains("test") && it.path.contains("resources"))}.each {
149+
sourceSet.allSource.findAll {
150+
!it.path.contains("build") &&
151+
!(it.path.contains("test") && it.path.contains("resources"))
152+
}.each {
150153
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
154+
if (!file.name.contains("json")) {
155+
BufferedReader r = new BufferedReader(new FileReader(file))
156+
def line, hasSPDX = false, hasTraditional = false
157+
while ((line = r.readLine()) != null) {
158+
if (line.contains("SPDX-License-Identifier")) {
159+
hasSPDX = true
160+
break
161+
}
162+
if (line.contains("http://www.apache.org/licenses/LICENSE-2.0")) {
163+
hasTraditional = true
164+
break
165+
}
158166
}
159-
if (line.contains("http://www.apache.org/licenses/LICENSE-2.0")) {
160-
hasTraditional = true
161-
break
167+
if (!hasSPDX) {
168+
if (hasTraditional) {
169+
noSPDX.add(file)
170+
} else {
171+
missing.add(file)
172+
}
162173
}
163174
}
164-
if (!hasSPDX) {
165-
if (hasTraditional) {
166-
noSPDX.add(file)
167-
} else {
168-
missing.add(file)
169-
}
170-
}
171-
}
172175
}
173176
}
174177

@@ -212,18 +215,12 @@ javadoc {
212215

213216
classpath = sourceSets.main.runtimeClasspath
214217

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

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

226-
227224
publishing {
228225
publications {
229226
shim(MavenPublication) {
@@ -235,10 +232,12 @@ publishing {
235232
name = 'JavaChaincodeShim'
236233
packaging = 'jar'
237234
description = 'Hyperledger Fabric Java Chaincode Shim'
238-
url = 'http://www.hyperledger.org/'
235+
url = 'https://hyperledger.github.io/fabric-chaincode-java/'
239236

240237
scm {
241-
url = 'https://github.com/hyperledger/fabric-chaincode-java.git'
238+
connection = 'scm:git:https://github.com/hyperledger/fabric-chaincode-java.git'
239+
developerConnection = 'scm:git:ssh://github.com:hyperledger/fabric-chaincode-java.git'
240+
url = 'https://github.com/hyperledger/fabric-chaincode-java'
242241
}
243242
licenses {
244243
license {
@@ -248,26 +247,16 @@ publishing {
248247
}
249248

250249
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-
}
266250
developer {
267251
id = 'denyeart'
268252
name = 'David Enyeart'
269253
270254
}
255+
developer {
256+
id = 'bestbeforetoday'
257+
name = 'Mark S. Lewis'
258+
259+
}
271260
}
272261
}
273262
}
@@ -276,17 +265,12 @@ publishing {
276265

277266
repositories {
278267
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-
268+
name = "Staging"
269+
url = layout.buildDirectory.dir('staging-deploy')
286270
}
287271

288272
maven {
289-
name = "GitHubPackages"
273+
name = "GitHub"
290274
url = "https://maven.pkg.github.com/hyperledger/fabric-chaincode-java"
291275
credentials {
292276
username = System.getenv("GITHUB_ACTOR")
@@ -296,26 +280,39 @@ publishing {
296280
}
297281
}
298282

299-
signing {
300-
println "Signing"
301-
if (project.findProperty('signing.key')) {
302-
def signingKey = project.findProperty('signing.key')
303-
def signingPassword = project.findProperty('signing.password')
304-
useInMemoryPgpKeys(signingKey, signingPassword)
305-
306-
sign publishing.publications.shim
307-
println "... signed"
308-
} else {
309-
println "... no keys to use "
283+
jreleaser {
284+
gitRootSearch = true
285+
signing {
286+
active = 'ALWAYS'
287+
armored = true
288+
verify = false
289+
}
290+
deploy {
291+
maven {
292+
mavenCentral {
293+
sonatype {
294+
active = 'ALWAYS'
295+
url = 'https://central.sonatype.com/api/v1/publisher'
296+
stagingRepository(layout.buildDirectory.dir('staging-deploy').get().toString())
297+
}
298+
}
299+
}
300+
}
301+
release {
302+
github {
303+
skipRelease = true
304+
skipTag = true
305+
token = 'EMPTY'
306+
}
310307
}
311308
}
312309

313310
// Need to specify the sourcesJar task BEFORE the java{withSourcesJar()} so that it picks up the duplicatesStratergy
314311
// otherwise this fails with a duplicates error.
315312
// (see https://github.com/gradle/gradle/issues/17236)
316313

317-
task sourcesJar(type: Jar) {
318-
duplicatesStrategy = 'include'
314+
tasks.register('sourcesJar', Jar) {
315+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
319316
archiveClassifier = 'sources'
320317
from sourceSets.main.allSource
321318
}
@@ -332,16 +329,16 @@ build.dependsOn licenseCheck
332329
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
333330
import org.gradle.api.tasks.testing.logging.TestLogEvent
334331

335-
tasks.withType(Test) {
332+
tasks.withType(Test).configureEach {
336333

337334
environment "CORE_PEER_LOCALMSPID", "mymsp"
338335

339336
testLogging {
340337
// set options for log level LIFECYCLE
341338
events TestLogEvent.FAILED,
342-
TestLogEvent.PASSED,
343-
TestLogEvent.SKIPPED,
344-
TestLogEvent.STANDARD_OUT
339+
TestLogEvent.PASSED,
340+
TestLogEvent.SKIPPED,
341+
TestLogEvent.STANDARD_OUT
345342
exceptionFormat = TestExceptionFormat.FULL
346343
showExceptions = true
347344
showCauses = true
@@ -350,22 +347,23 @@ tasks.withType(Test) {
350347
// set options for log level DEBUG and INFO
351348
debug {
352349
events TestLogEvent.STARTED,
353-
TestLogEvent.FAILED,
354-
TestLogEvent.PASSED,
355-
TestLogEvent.SKIPPED,
356-
TestLogEvent.STANDARD_ERROR,
357-
TestLogEvent.STANDARD_OUT
350+
TestLogEvent.FAILED,
351+
TestLogEvent.PASSED,
352+
TestLogEvent.SKIPPED,
353+
TestLogEvent.STANDARD_ERROR,
354+
TestLogEvent.STANDARD_OUT
358355
exceptionFormat = TestExceptionFormat.FULL
359356
}
360357
info.events = debug.events
361358
info.exceptionFormat = debug.exceptionFormat
362359

363-
afterSuite { desc, result ->
360+
afterSuite {desc, result ->
364361
if (!desc.parent) { // will match the outermost suite
365362
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
366363
def startItem = '| ', endItem = ' |'
367364
def repeatLength = startItem.length() + output.length() + endItem.length()
368-
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
365+
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' +
366+
('-' * repeatLength))
369367
}
370368
}
371369
}

0 commit comments

Comments
 (0)