-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.gradle
More file actions
327 lines (296 loc) · 13.4 KB
/
Copy pathbuild.gradle
File metadata and controls
327 lines (296 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
* Copyright (c) 2015-2021 Dell Inc., or its subsidiaries. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.github.jk1.license.render.InventoryHtmlReportRenderer
plugins {
id 'idea'
id 'eclipse'
id 'java'
id 'jacoco'
id 'com.github.jk1.dependency-license-report' version '3.0.1' apply false
id 'org.ajoberstar.git-publish' version '5.1.2'
id 'nebula.release' version '21.0.0'
}
// name of the github project repository
ext.githubProjectName = 'smart-client-java'
// URL to github project
ext.githubProjectUrl = "https://github.com/EMCECS/${githubProjectName}"
// git remote scm address
ext.githubScmUrl = "scm:git@github.com:EMCECS/${githubProjectName}.git"
// git remote https address
ext.githubRemoteUrl = "https://github.com/EMCECS/${githubProjectName}.git"
// license info
ext.licenseName = 'Apache License 2.0'
ext.licenseUrl = 'https://www.apache.org/licenses/'
subprojects {
apply plugin: 'java-library'
apply plugin: 'jacoco'
apply plugin: 'com.github.jk1.dependency-license-report'
apply plugin: 'distribution'
apply plugin: 'signing'
apply plugin: 'maven-publish'
group 'com.emc.ecs'
defaultTasks 'distZip'
repositories {
mavenCentral()
mavenLocal()
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
}
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
tasks.javadocJar.dependsOn javadoc
task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
jar {
doFirst {
manifest {
attributes 'Implementation-Version': project.version,
'Class-Path': configurations.runtimeClasspath.collect { it.getName() }.join(' ')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = project.name
description = providers.provider { project.description ?: project.name }
url = githubProjectUrl
scm {
url = githubProjectUrl
connection = githubScmUrl
developerConnection = githubScmUrl
}
licenses {
license {
name = licenseName
url = licenseUrl
distribution = 'repo'
}
}
developers {
developer {
id = 'EMCECS'
name = 'Dell EMC ECS'
}
}
}
}
}
repositories {
maven {
// OSSRH is EOL (June 30 2025). Use the Central Portal OSSRH Staging API
// compatibility service. Credentials must now be a Portal user token
// (generate at https://central.sonatype.com/account) — not the old OSSRH password.
name = 'centralPortalOssrhStaging'
url = 'https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/'
credentials {
username = findProperty('sonatypeUser') ?: ''
password = findProperty('sonatypePass') ?: ''
}
}
}
}
signing {
// Modern GPG keys (Ed25519/Curve25519/ECDH = algorithm 18) cannot be parsed
// by the signing plugin's bundled BouncyCastle when reading secring.gpg.
// useGpgCmd() shells out to the local `gpg` binary instead, which handles
// every algorithm natively. Requires gpg on PATH (you already have it,
// since you exported secring.gpg with it).
//
// Properties consumed by useGpgCmd():
// signing.gnupg.keyName ← mapped from -PsigningKeyId below
// signing.gnupg.passphrase ← mapped from -PsigningPass below
// signing.gnupg.executable defaults to 'gpg' (override if needed)
// signing.gnupg.homeDir defaults to ~/.gnupg
useGpgCmd()
// hasTask(String) resolves relative paths against the ROOT project, so
// hasTask('publish') was looking for :publish (which does not exist) and
// always returned false — meaning signing was never required and no .asc
// files were uploaded. Match by task name across all projects instead.
required {
gradle.taskGraph.allTasks.any { t ->
t.name == 'publish' || t.name == 'publishToPortal' ||
t.name == 'publishMavenJavaPublicationToCentralPortalOssrhStagingRepository'
}
}
sign publishing.publications.mavenJava
}
licenseReport {
renderers = [new InventoryHtmlReportRenderer()]
}
distributions {
main {
contents {
from jar
from javadocJar
from sourcesJar
from('.') {
include '*.txt'
}
into('3rd-party-licenses') {
from generateLicenseReport
}
into('lib') {
from configurations.runtimeClasspath
}
}
}
}
// allow typing in credentials
// note: this only works when run without the Gradle daemon (--no-daemon).
// if that's not possible, it's best to read passwords into env. variables and set these properties on the gradle
// command line ( -PsigningPass="${SIGNING_PASS}" -PsonatypePass="${SONATYPE_PASS}" )
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.allTasks.any { t -> t.name == 'publish' || t.name == 'publishToPortal' || t.name == 'publishMavenJavaPublicationToCentralPortalOssrhStagingRepository' }) {
if (!rootProject.hasProperty('signingKeyId'))
rootProject.ext.signingKeyId = new String(System.console().readLine('\nSigning key id: '))
if (!rootProject.hasProperty('signingPass'))
rootProject.ext.signingPass = new String(System.console().readPassword('\nSigning key passphrase: '))
if (!rootProject.hasProperty('sonatypeUser'))
rootProject.ext.sonatypeUser = new String(System.console().readLine('\nSonatype username: '))
if (!rootProject.hasProperty('sonatypePass'))
rootProject.ext.sonatypePass = new String(System.console().readPassword('\nSonatype password: '))
// Legacy properties (unused by useGpgCmd() but kept for reference).
ext.'signing.keyId' = rootProject.ext.signingKeyId
ext.'signing.password' = rootProject.ext.signingPass
// useGpgCmd() reads these:
ext.'signing.gnupg.keyName' = rootProject.ext.signingKeyId
ext.'signing.gnupg.passphrase' = rootProject.ext.signingPass
}
}
}
ext.aggregatedDocsDir = "${layout.buildDirectory.get().asFile}/aggregatedDocs"
task aggregateDocs {
doLast {
if (project.hasProperty('release.stage') && project.ext['release.stage'] == 'final') {
subprojects.each { sp ->
copy {
from sp.javadoc.destinationDir
into "${aggregatedDocsDir}/${sp.name}/latest"
}
}
}
subprojects.each {sp ->
copy {
from sp.javadoc.destinationDir
into "${aggregatedDocsDir}/${sp.name}/${sp.version}"
}
}
}
}
tasks.aggregateDocs.dependsOn subprojects.javadoc
gitPublish {
repoUri = githubRemoteUrl
branch = 'gh-pages'
contents {
from aggregatedDocsDir
}
preserve { include '**/*' }
}
tasks.gitPublishPush.dependsOn aggregateDocs
// After uploading via maven-publish (a "Maven-API-like" plugin that only does PUTs),
// we must POST to the manual upload endpoint so the deployment becomes visible in the
// Central Publisher Portal (https://central.sonatype.com/publishing/deployments).
//
// Multi-module note: all three subprojects upload to the same staging repository
// (the OSSRH Staging API isolates by IP, not by artifact). One POST therefore
// transfers ALL three modules together as a single Portal deployment. The Portal
// validates them as a unit — if any module fails (missing pom field, bad signature,
// etc.) the whole deployment is rejected, which is what you want for a multi-module
// release.
//
// Auth quirk: /manual/* endpoints require Bearer <base64(user:pass)>, NOT Basic.
// Same credentials as the PUT upload, different scheme keyword.
task publishToPortal {
group = 'publishing'
description = 'Signals the OSSRH Staging API to transfer all subprojects\' staged artifacts to the Central Publisher Portal for review/release'
dependsOn subprojects.collect { "${it.path}:publish" }
doLast {
def namespace = 'com.emc.ecs' // matches subprojects.group
def portalUser = rootProject.findProperty('sonatypeUser') ?: ''
def portalPass = rootProject.findProperty('sonatypePass') ?: ''
if (!portalUser || !portalPass) {
throw new GradleException('sonatypeUser/sonatypePass not set — generate a Portal token at https://central.sonatype.com/account')
}
def endpoint = "https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/${namespace}?publishing_type=user_managed"
def bearer = java.util.Base64.encoder.encodeToString(
"${portalUser}:${portalPass}".getBytes('UTF-8'))
logger.lifecycle(" Signalling Central Portal to transfer staged deployment for namespace: ${namespace}")
logger.lifecycle(" Subprojects included: ${subprojects*.name.join(', ')}")
def conn = (java.net.HttpURLConnection) new URL(endpoint).openConnection()
try {
conn.requestMethod = 'POST'
conn.connectTimeout = 30_000
conn.readTimeout = 120_000
conn.setRequestProperty('Authorization', "Bearer ${bearer}")
conn.setRequestProperty('Content-Length', '0')
conn.setRequestProperty('Accept', 'application/json')
conn.connect()
def code = conn.responseCode
if (code in [200, 201, 202, 204]) {
logger.lifecycle(" Deployment transferred to Central Publisher Portal (HTTP ${code}).")
logger.lifecycle(' Review and publish at: https://central.sonatype.com/publishing/deployments')
} else {
def body = '(no body)'
try { if (conn.errorStream) body = new String(conn.errorStream.bytes, 'UTF-8') } catch (ignored) { }
def hint = (code == 401)
? ' → 401: Portal user token is invalid/expired. Regenerate at https://central.sonatype.com/account\n'
: (code == 404)
? ' → 404: No staging repo found for IP. Did the upload actually run? Check that signing succeeded.\n'
: ''
throw new GradleException(
"Failed to transfer deployment to Central Publisher Portal: HTTP ${code}\n${hint}${body}")
}
} finally {
conn.disconnect()
}
}
}
// NOTE: previously this only depended on test, gitPublishPush, distZip — it never
// triggered the publish task, so historical `release` runs created git tags but
// never uploaded artifacts to Maven Central. publishToPortal fixes that.
tasks.release.dependsOn subprojects.test, publishToPortal, gitPublishPush, subprojects.distZip
clean {
delete aggregatedDocsDir
}
// allow typing in credentials
// note: this only works when run without the Gradle daemon (--no-daemon).
// if that's not possible, it's best to read passwords into env. variables and set these properties on the gradle
// command line ( -PgitPassword="${GIT_PASSWORD}" )
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(':gitPublishPush') || taskGraph.hasTask(':release')) {
if (!rootProject.hasProperty('gitUsername'))
rootProject.ext.gitUsername = new String(System.console().readLine('\nGit username: '))
if (!rootProject.hasProperty('gitPassword'))
rootProject.ext.gitPassword = new String(System.console().readPassword('\nGit password: '))
System.setProperty('org.ajoberstar.grgit.auth.username', rootProject.ext.gitUsername)
System.setProperty('org.ajoberstar.grgit.auth.password', rootProject.ext.gitPassword)
}
}