Skip to content

Commit 5fcd441

Browse files
committed
BUILD: use JReleaser for publishing to Maven Central
1 parent 7f14deb commit 5fcd441

File tree

3 files changed

+42
-66
lines changed

3 files changed

+42
-66
lines changed

build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import aQute.bnd.gradle.Bundle
22

3-
group = 'info.picocli'
4-
description = 'Java command line parser with both an annotations API and a programmatic API. Usage help with ANSI styles and colors. Autocomplete. Nested subcommands. Easily included as source to avoid adding a dependency.'
5-
version = "$projectVersion"
6-
ext.moduleName = 'info.picocli'
7-
83
buildscript {
94
apply from: 'dependencies.gradle'
105

@@ -23,6 +18,15 @@ buildscript {
2318
}
2419
}
2520

21+
plugins {
22+
id 'org.jreleaser' version '1.17.0'
23+
}
24+
25+
group = 'info.picocli'
26+
description = 'Java command line parser with both an annotations API and a programmatic API. Usage help with ANSI styles and colors. Autocomplete. Nested subcommands. Easily included as source to avoid adding a dependency.'
27+
version = "$projectVersion"
28+
ext.moduleName = 'info.picocli'
29+
2630
apply plugin: 'org.beryx.jar' // for compiling module-info on Java 8
2731
apply plugin: 'io.codearte.nexus-staging'
2832

gradle/publish-mavencentral.gradle

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// This build file is based on/inspired by https://autsoft.net/publishing-an-android-library-to-mavencentral-in-2019/
22

33
apply plugin: 'java'
4-
apply plugin: 'distribution'
54
apply plugin: 'maven-publish'
6-
apply plugin: 'signing'
7-
85

96
task javadocJar(type: Jar, dependsOn: javadoc) {
107
from javadoc.destinationDir
@@ -33,48 +30,11 @@ artifacts {
3330
tasks.withType(GenerateModuleMetadata) {
3431
enabled = false // fix for https://github.com/remkop/picocli/issues/1152
3532
}
36-
distributions {
37-
main {
38-
distributionBaseName = "${project.name}-all"
39-
contents {
40-
from jar
41-
from javadocJar
42-
from sourcesJar
43-
from testJar
44-
from testSourcesJar
45-
from ('LICENSE')
46-
from ("$rootDir/RELEASE-NOTES.md")
47-
}
48-
}
49-
}
5033

5134
// different for each module
5235
group = PUBLISH_GROUP_ID
5336
version = PUBLISH_VERSION
5437

55-
ext["signing.keyId"] = ''
56-
ext["signing.password"] = ''
57-
ext["signing.secretKeyRingFile"] = ''
58-
ext["ossrhUsername"] = ''
59-
ext["ossrhPassword"] = ''
60-
ext["sonatypeStagingProfileId"] = ''
61-
62-
File secretPropsFile = project.rootProject.file('local.properties')
63-
if (secretPropsFile.exists()) {
64-
Properties p = new Properties()
65-
p.load(new FileInputStream(secretPropsFile))
66-
p.each { name, value ->
67-
ext[name] = value
68-
}
69-
} else {
70-
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
71-
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
72-
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
73-
ext["ossrhUsername"] = System.getenv('MAVEN_OSS_USER')
74-
ext["ossrhPassword"] = System.getenv('MAVEN_OSS_PASSWORD')
75-
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
76-
}
77-
7838
publishing {
7939
publications {
8040
release(MavenPublication) {
@@ -118,27 +78,8 @@ publishing {
11878
}
11979
repositories {
12080
maven {
121-
name = "sonatype"
122-
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
123-
124-
credentials {
125-
username = ossrhUsername
126-
password = ossrhPassword
127-
}
81+
url = rootProject.layout.buildDirectory.dir('staging-deploy')
12882
}
12983
}
13084
}
13185

132-
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
133-
134-
signing {
135-
required = { isReleaseVersion && gradle.taskGraph.hasTask("publish") }
136-
sign publishing.publications
137-
}
138-
139-
nexusStaging {
140-
packageGroup = PUBLISH_GROUP_ID
141-
stagingProfileId = '5db36034f05d47' // Log in to https://oss.sonatype.org/, go to Staging profiles, select your profile, and look at the ID in the URL
142-
username = ossrhUsername
143-
password = ossrhPassword
144-
}

gradle/release-tasks.gradle

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
/**
2+
* JReleaser expects all artifacts
3+
* (created by the publishing config in gradle/publish-mavencentral.gradle)
4+
* to exist in "${rootProject.projectDir}/build/staging-deploy" directory.
5+
* JReleaser is only configured once, on the top-level project (not for each sub-project).
6+
*
7+
* See: https://jreleaser.org/guide/latest/examples/maven/maven-central.html
8+
*/
9+
jreleaser {
10+
signing {
11+
active = 'RELEASE'
12+
armored = true
13+
}
14+
deploy {
15+
maven {
16+
nexus2 {
17+
'maven-central' {
18+
active = 'RELEASE'
19+
url = 'https://oss.sonatype.org/service/local'
20+
snapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
21+
closeRepository = true
22+
releaseRepository = false
23+
stagingRepository('build/staging-deploy')
24+
}
25+
}
26+
}
27+
}
28+
}
29+
130
task bumpReadmeVersion {
231
doLast {
332
// README.md
@@ -193,7 +222,9 @@ Release procedure:
193222
cd picocli-tests-java567 & set JAVA_HOME=C:\apps\jdk1.5.0_22\&& echo ++%JAVA_HOME%++ && gradlew clean build --no-daemon
194223
11. commit -m "Release picocli version ..."
195224
12. tag v$version
196-
13 ./gradlew publishReleasePublicationToSonatypeRepository - creates a Sonatype staging repository, and uploads artifacts
225+
13a. gradlew jreleaserConfig
226+
13b. gradlew clean pub jreleaserFullRelease --dryrun
227+
13c. gradlew clean pub jreleaserFullRelease
197228
14. Close the Sonatype info/picocli staging repo:
198229
a. Manually: Log in to https://oss.sonatype.org/ and in the menu on the left, select Staging repositories.
199230
Click the close button in the GUI and watch progress in the Activity tab.

0 commit comments

Comments
 (0)