-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild.gradle
More file actions
369 lines (309 loc) · 10.4 KB
/
build.gradle
File metadata and controls
369 lines (309 loc) · 10.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
id 'com.adarshr.test-logger' version '2.1.1'
id 'org.unbroken-dome.test-sets' version '4.0.0'
}
apply plugin: 'jacoco'
group libGroup
version libVersion
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
repositories {
mavenCentral()
jcenter() {
content {
includeModule("org.testng", "testng")
}
}
}
/**
* Defines test sets:
* - Unit Tests (test) <-- existing default
* - Integration (integration)
*
* @plugin org.unbroken-dome.test-sets
*/
testSets {
integration
}
/**
* Defines all dependencies.
*
* @see https://docs.gradle.org/6.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api 'com.google.code.gson:gson:2.10.1'
api 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'org.apache.commons:commons-text:1.2'
implementation 'javax.json:javax.json-api:1.0' // Java EE interfaces
runtimeOnly 'org.glassfish:javax.json:1.1' // implementation for above interfaces
implementation 'commons-codec:commons-codec:1.10'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.1'
testImplementation 'org.powermock:powermock-release-with-testng-mockito-dependencies:1.6.2'
testImplementation 'org.testng:testng:7.4.0'
integrationImplementation 'org.seleniumhq.selenium:selenium-java:4.11.0'
}
/**
* Generates Javadoc for the SDK.
*
* @plugin java
*/
javadoc {
destinationDir = file('docs')
options.header = libDescription
options.windowTitle = "${libName} - ${libVersion}"
options.addBooleanOption('notimestamp', true)
}
/**
* Customizes the jar MANIFEST.MF for generated jars.
*
* @plugin java
*/
jar {
manifest {
attributes('Implementation-Title': libName,
'Implementation-Version': libVersion)
}
}
/**
* Configures all test tasks.
*
* @plugin com.adarshr.test-logger
* @plugin java
*/
tasks.withType(Test) {
useTestNG {
preserveOrder true
}
testlogger {
theme 'mocha'
showStandardStreams true
showPassedStandardStreams false
showSkippedStandardStreams false
showFailedStandardStreams true
showFullStackTraces true
}
}
check.dependsOn integration
/**
* Configures coverage reporting.
*
* @plugin jacoco
*/
jacoco {
reportsDirectory = file("${buildDir}/reports/coverage")
}
/**
* Generates coverage reports for the unit tests.
*
* @plugin jacoco
*/
jacocoTestReport {
reports {
html.enabled = true
html.destination = file("${buildDir}/reports/coverage/test/html")
xml.enabled = true
xml.destination = file("${buildDir}/reports/coverage/test/report.xml")
}
}
/**
* Generates coverage reports for the integration tests.
*
* @plugin jacoco
*/
jacocoIntegrationReport {
dependsOn integration
reports {
html.enabled = true
html.destination = file("${buildDir}/reports/coverage/integration/html")
xml.enabled = true
xml.destination = file("${buildDir}/reports/coverage/integration/report.xml")
}
}
/**
* Generates all coverage reports after running tests.
*
* @plugin jacoco
*/
task coverage {
dependsOn check
dependsOn jacocoTestReport
dependsOn jacocoIntegrationReport
}
/**
* Generates updated markdown documentation using the markdown template files.
*/
task markdown(type: Copy) {
def date = new Date()
def licenseYear = date.format('yyyy')
from './'
into './'
include '*.mdt'
rename '^(.*)\\.mdt$', '$1.md'
expand(libGroup: libGroup, libName: libName, libVersion: libVersion, year: licenseYear)
filteringCharset = 'UTF-8'
}
/**
* Configures packaging of modules/artifacts to publish.
*
* @plugin maven-publish
*/
publishing {
publications {
main(MavenPublication) {
from components.java
artifactId libName
pom {
// https://central.sonatype.org/publish/requirements/#sufficient-metadata
name = libName
description = 'Java SDK for the Smartcar platform'
url = 'https://github.com/smartcar/java-sdk'
licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
}
}
developers {
developer {
id = 'smartcar'
name = 'Smartcar'
email = 'hello@smartcar.com'
}
}
scm {
connection = 'scm:git:git://github.com/smartcar/java-sdk.git'
developerConnection = 'scm:git:ssh://github.com:smartcar/java-sdk.git'
url = 'https://github.com/smartcar/java-sdk.git'
}
}
}
}
}
/**
* Requires the following environment variables to be set:
* - ORG_GRADLE_PROJECT_signingKey
* - ORG_GRADLE_PROJECT_signingPassword
*
* @see https://docs.gradle.org/current/userguide/signing_plugin.html#sec:in-memory-keys
*/
signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
// Always set up signing but only require it if keys are available
required { signingKey != null && signingPassword != null }
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys signingKey, signingPassword
}
sign publishing.publications.main
}
/**
* Custom task to upload artifacts to Sonatype Central
* Requires the following environment variables to be set:
* - ORG_GRADLE_PROJECT_sonatypeUsername (Central Portal username)
* - ORG_GRADLE_PROJECT_sonatypePassword (Central Portal password)
*/
task uploadToSonatypeCentral {
group = 'publishing'
description = 'Uploads signed artifacts to Sonatype Central Portal'
dependsOn 'signMainPublication'
doLast {
def username = findProperty("sonatypeUsername")
def password = findProperty("sonatypePassword")
if (!username || !password) {
throw new GradleException("Missing Sonatype Central credentials. Set ORG_GRADLE_PROJECT_sonatypeUsername and ORG_GRADLE_PROJECT_sonatypePassword")
}
// Get the published artifacts from local repository
def localRepo = "${System.getProperty('user.home')}/.m2/repository"
def groupPath = libGroup.replace('.', '/')
def artifactPath = "${localRepo}/${groupPath}/${libName}/${libVersion}"
println "Preparing upload bundle for ${libGroup}:${libName}:${libVersion}"
// Create a temporary directory for the bundle with proper Maven structure
def bundleDir = file("${buildDir}/sonatype-bundle")
def mavenDir = file("${bundleDir}/${groupPath}/${libName}/${libVersion}")
mavenDir.mkdirs()
// Copy all artifacts to proper Maven directory structure
copy {
from artifactPath
into mavenDir
include '*.jar', '*.pom', '*.module', '*.asc', '*.md5', '*.sha1'
}
// Generate missing checksums and signatures if needed
def artifactFiles = fileTree(mavenDir).matching {
include '*.jar', '*.pom', '*.module'
exclude '*.asc', '*.md5', '*.sha1'
}
artifactFiles.each { file ->
def fileName = file.name
// Generate MD5 checksum
def md5File = new File(mavenDir, "${fileName}.md5")
if (!md5File.exists()) {
def md5Hash = java.security.MessageDigest.getInstance("MD5")
.digest(file.bytes)
.encodeHex()
.toString()
md5File.text = md5Hash
println "Generated MD5 for ${fileName}: ${md5Hash}"
}
// Generate SHA1 checksum
def sha1File = new File(mavenDir, "${fileName}.sha1")
if (!sha1File.exists()) {
def sha1Hash = java.security.MessageDigest.getInstance("SHA-1")
.digest(file.bytes)
.encodeHex()
.toString()
sha1File.text = sha1Hash
println "Generated SHA1 for ${fileName}: ${sha1Hash}"
}
// Check for signature
def sigFile = new File(mavenDir, "${fileName}.asc")
if (!sigFile.exists()) {
println "Warning: Missing signature for ${fileName}"
}
}
// List all files in the bundle
println "Bundle contents:"
fileTree(bundleDir).each { file ->
def relativePath = bundleDir.toPath().relativize(file.toPath()).toString()
println " ${relativePath}"
}
// Create the upload bundle (zip file)
def bundleFile = file("${buildDir}/sonatype-bundle.zip")
ant.zip(destfile: bundleFile) {
fileset(dir: bundleDir)
}
println "Created bundle: ${bundleFile.absolutePath} (${bundleFile.length()} bytes)"
// Upload to Sonatype Central using curl
def curlCommand = [
'curl', '-X', 'POST',
'--header', 'accept: application/json',
'--form', "bundle=@${bundleFile.absolutePath}",
'--user', "${username}:${password}",
'--silent', '--show-error',
'https://central.sonatype.com/api/v1/publisher/upload'
]
println "Uploading to Sonatype Central..."
def process = curlCommand.execute()
def outputStream = new ByteArrayOutputStream()
def errorStream = new ByteArrayOutputStream()
process.consumeProcessOutput(outputStream, errorStream)
process.waitFor()
def output = outputStream.toString()
def error = errorStream.toString()
if (process.exitValue() == 0) {
println "Upload successful!"
println "Response: ${output}"
} else {
println "Upload failed!"
println "Error: ${error}"
println "Output: ${output}"
throw new GradleException("Failed to upload to Sonatype Central")
}
}
}