-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
build.gradle
435 lines (383 loc) · 15.1 KB
/
build.gradle
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
buildscript {
def properties = new Properties()
properties.load(new FileInputStream("${projectDir}/dependencies.list"))
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
def currentVersion = file("${projectDir}/version.txt").text.trim()
// Find property in either System environment or Gradle properties.
// If set in both places, Gradle properties win.
def getPropertyValueOrThrow(String propertyName) {
def value = System.getenv(propertyName)
if (project.hasProperty(propertyName)) {
value = project.getProperty(propertyName)
}
if (value == null || value.trim().isEmpty()) {
throw new GradleException("Could not find '$propertyName'. " +
"Most be provided as either environment variable or " +
"a Gradle property.")
}
return value
}
// Shared configuration that copies relevant properties from the root level and parse them on to
// child projects.
def copyProperties = {
if (project.hasProperty('buildTargetABIs')) {
// Valid options: armeabi-v7a, arm64-v8a, x86, x86_64
startParameter.projectProperties += [buildTargetABIs: project.getProperty('buildTargetABIs')]
}
if (project.hasProperty('coreSourcePath')) {
def absolutePath = file(project.getProperty('coreSourcePath')).absolutePath
startParameter.projectProperties += [coreSourcePath: absolutePath]
}
if (project.hasProperty('s3cfg')) {
startParameter.projectProperties += [s3cfg: project.getProperty('s3cfg')]
}
if (project.hasProperty('enableLTO')) {
startParameter.projectProperties += [enableLTO: project.getProperty('enableLTO')]
}
if (project.hasProperty('buildCore')) {
startParameter.projectProperties += [buildCore: project.getProperty('buildCore')]
}
if (project.hasProperty('signBuild')) {
startParameter.projectProperties += [signBuild: project.getProperty('signBuild')]
}
if (project.hasProperty('signPassword')) {
startParameter.projectProperties += [signPassword: project.getProperty('signPassword')]
}
if (project.hasProperty('signSecretRingFile')) {
startParameter.projectProperties += [signSecretRingFile: project.getProperty('signSecretRingFile')]
}
if (project.hasProperty('ossrhUsername')) {
startParameter.projectProperties += [ossrhUsername: project.getProperty('ossrhUsername')]
}
if (project.hasProperty('ossrhPassword')) {
startParameter.projectProperties += [ossrhPassword: project.getProperty('ossrhPassword')]
}
}
task assembleAnnotations(type:GradleBuild) {
group = 'Build'
description = 'Assemble the Realm annotations'
buildFile = file('realm-annotations/build.gradle')
tasks = ['assemble']
}
task installAnnotations(type:GradleBuild) {
group = 'Install'
description = 'Install the jar realm-annotations into mavenLocal()'
buildFile = file('realm-annotations/build.gradle')
tasks = ['publishToMavenLocal']
}
task assembleTransformer(type:GradleBuild) {
group = 'Build'
description = 'Assemble the Realm transformer'
dependsOn installAnnotations
buildFile = file('realm-transformer/build.gradle')
tasks = ['assemble']
}
task installTransformer(type:GradleBuild) {
group = 'Install'
description = 'Install the jar realm-transformer into mavenLocal()'
dependsOn installAnnotations
buildFile = file('realm-transformer/build.gradle')
tasks = ['publishToMavenLocal']
}
task installBuildTransformer(type:GradleBuild) {
group = 'Install'
description = 'Install the jar realm-library-build-transformer into mavenLocal()'
buildFile = file('library-build-transformer/build.gradle')
tasks = ['publishToMavenLocal']
}
task assembleRealm(type:GradleBuild) {
group = 'Build'
description = 'Assemble the Realm project'
dependsOn installAnnotations
dependsOn installTransformer
dependsOn installBuildTransformer
buildFile = file('realm/build.gradle')
tasks = ['assemble', 'javadocJar', 'sourcesJar']
configure copyProperties
}
task checkExamples(type:GradleBuild) {
group = 'Test'
description = 'Run the JVM tests and checks the examples'
buildFile = file('examples/build.gradle')
tasks = ['check']
configure copyProperties
}
task checkRealm(type:GradleBuild) {
group = 'Test'
description = 'Run the JVM tests and checks Realm project'
buildFile = file('realm/build.gradle')
tasks = ['check']
configure copyProperties
}
task check {
group = 'Test'
description = 'Run the JVM tests and checks in the realm and examples projects'
dependsOn checkRealm
dependsOn checkExamples
}
task assembleUnitTests(type:GradleBuild) {
group = 'Build'
description = 'Assemble Android unit tests of the Realm project'
dependsOn installTransformer
buildFile = file('realm/build.gradle')
tasks = ['assembleAndroidTest']
configure copyProperties
}
task connectedUnitTests(type:GradleBuild) {
group = 'Test'
description = 'Run the Android unit tests of the Realm project'
dependsOn installTransformer
buildFile = file('realm/build.gradle')
tasks = ['connectedAndroidTest']
configure copyProperties
}
task assembleBenchmarks(type:GradleBuild) {
group = 'Build'
description = 'Assemble benchmark tests for the library '
dependsOn installTransformer
buildFile = file('library-benchmarks/build.gradle')
tasks = ['assembleAndroidTest']
configure copyProperties
}
task connectedBenchmarks(type:GradleBuild) {
group = 'Test'
description = 'Run all the benchmark tests for the library '
dependsOn installTransformer
buildFile = file('library-benchmarks/build.gradle')
tasks = ['connectedAndroidTest']
configure copyProperties
}
task installRealm(type:GradleBuild) {
group = 'Install'
description = 'Install the artifacts of Realm libraries into mavenLocal()'
dependsOn installTransformer
dependsOn installBuildTransformer
buildFile = file('realm/build.gradle')
tasks = ['publishToMavenLocal']
configure copyProperties
}
task assembleGradlePlugin(type:GradleBuild) {
group = 'Build'
description = 'Assemble the Realm Gradle plugin'
dependsOn installRealm
dependsOn installTransformer
buildFile = file('gradle-plugin/build.gradle')
tasks = ['assemble']
}
task installGradlePlugin(type:GradleBuild) {
description = 'Install the Realm Gradle plugin into mavenLocal()'
group = 'Install'
dependsOn installRealm
dependsOn installTransformer
buildFile = file('gradle-plugin/build.gradle')
tasks = ['publishToMavenLocal']
}
task installRealmJava(type:Task) {
dependsOn installGradlePlugin
dependsOn installRealm
group = 'Install'
description = 'Install the Realm library and Gradle plugin into mavenLocal()'
}
task assembleExamples(type:GradleBuild) {
dependsOn installGradlePlugin
dependsOn installRealm
group = 'Build'
description = 'Assemble the Realm examples'
buildFile = file('examples/build.gradle')
tasks = ['assemble']
}
task monkeyExamples(type:GradleBuild) {
dependsOn installGradlePlugin
dependsOn installRealm
group = 'Build'
description = 'Run the monkey tests on the Realm examples'
buildFile = file('examples/build.gradle')
tasks = ['monkeyRelease']
}
task javadoc(type:GradleBuild) {
description = 'Generate the Javadoc Jar for the Realm project'
group = 'Docs'
buildFile = file('realm/build.gradle')
tasks = ['javadocJar']
configure copyProperties
}
task uploadJavadoc {
group = 'Release'
description = 'Upload Java and Kotlin docs to S3'
dependsOn javadoc
doLast {
def awsAccessKey = getPropertyValueOrThrow("SDK_DOCS_AWS_ACCESS_KEY")
def awsSecretKey = getPropertyValueOrThrow("SDK_DOCS_AWS_SECRET_KEY")
// Upload two copies, to 'latest' and a versioned folder for posterity.
// Symlinks would have been safer and faster, but this is not supported by S3.
[ "${currentVersion}", "latest"].forEach { version ->
exec {
commandLine 's3cmd', 'put', '--recursive', '--acl-public', "--access_key=${awsAccessKey}", "--secret_key=${awsSecretKey}", 'realm/realm-library/build/docs/javadoc/', "s3://realm-sdks/realm-sdks/java/${version}/"
}
// The stylesheet is being uploaded with the wrong Content-Type header, which causes the stylesheet to not be applied in some browsers.
// So we need to modify the stylesheet after it has been uploaded.
exec {
commandLine 's3cmd', 'modify', "--access_key=${awsAccessKey}", "--secret_key=${awsSecretKey}", "--debug", '--add-header=Content-Type: text/css', "s3://realm-sdks/realm-sdks/java/${version}/stylesheet.css"
}
// Upload Kotlin extension docs to a subdirectory of the Javadoc. This should not conflict with the Javadoc folder layout.
exec {
commandLine 's3cmd', 'put', '--recursive', '--acl-public', "--access_key=${awsAccessKey}", "--secret_key=${awsSecretKey}", 'realm/kotlin-extensions/build/dokka/', "s3://realm-sdks/realm-sdks/java/${version}/kotlin-extensions/"
}
}
}
}
task sourcesJar(type:GradleBuild) {
description = 'Generate the sources Jar for the Realm project'
group = 'Docs'
buildFile = file('realm/build.gradle')
tasks = ['sourcesJar']
configure copyProperties
}
task assemble {
group 'Build'
description = 'Build Realm, the Gradle plugin and the examples'
dependsOn assembleExamples
}
task distributionJniUnstrippedPackage(type:Zip) {
description = 'Generate native libs package with debug symbols'
group = 'Artifact'
archiveName = "realm-java-jni-libs-unstripped-${currentVersion}.zip"
destinationDir = file("${buildDir}/outputs/distribution")
from("realm/realm-library/build/outputs/jniLibs-unstripped") {
include '**/*.so'
}
}
task cleanRealm(type:GradleBuild) {
description = 'Clean the Realm project'
group = 'Clean'
buildFile = file('realm/build.gradle')
tasks = ['clean']
configure copyProperties
}
task cleanGradlePlugin(type:GradleBuild) {
description = 'Clean the Realm Gradle plugin project'
group = 'Clean'
buildFile = file('gradle-plugin/build.gradle')
tasks = ['clean']
}
task cleanExamples(type:GradleBuild) {
description = 'Clean the Realm examples'
group = 'Clean'
buildFile = file('examples/build.gradle')
tasks = ['clean']
}
task cleanLocalMavenRepos(type:Delete) {
description = 'Remove any Realm artifacts from the local Maven repositories'
group = 'Clean'
delete "${System.env.HOME}/.m2/repository/io/realm"
}
task clean {
description = 'Perform all the other clean tasks'
group = 'Clean'
cleanLocalMavenRepos.dependsOn cleanRealm
cleanLocalMavenRepos.dependsOn cleanGradlePlugin
cleanLocalMavenRepos.dependsOn cleanExamples
dependsOn cleanLocalMavenRepos
}
task manualClean {
description = 'Clean build files without using clean tasks defined in sub projects'
group = 'Clean'
doLast {
// clean 'build' directories
exec {
workingDir "${rootDir}"
commandLine 'find', '.', '-type', 'd', '-name', 'build', '-print', '-exec', 'rm', '-rf', '{}', ';', '-prune'
}
// clean '.externalNativeBuild' directories
exec {
workingDir "${rootDir}"
commandLine 'find', '.', '-type', 'd', '-name', '.externalNativeBuild', '-print', '-exec', 'rm', '-rf', '{}', ';', '-prune'
}
// clean '.gradle' directories except one in the root
exec {
workingDir "${rootDir}"
commandLine 'find', '.', '-mindepth', '2', '-type', 'd', '-name', '.gradle', '-print', '-exec', 'rm', '-rf', '{}', ';', '-prune'
}
// clean ${System.env.HOME}/.m2/repository/io/realm
exec {
workingDir "${rootDir}"
commandLine 'sh', '-c', "echo \"${System.env.HOME}/.m2/repository/io/realm\" && rm -rf \"${System.env.HOME}/.m2/repository/io/realm\""
}
}
}
task uploadDistributionPackage {
group = 'Release'
description = 'Upload the distribution package to S3'
dependsOn distributionJniUnstrippedPackage
def s3AccessKey = "${ -> getPropertyValueOrThrow('REALM_S3_ACCESS_KEY')}"
def s3SecretKey = "${ -> getPropertyValueOrThrow('REALM_S3_SECRET_KEY')}"
doLast {
// Check that zip file exists. Creating the zip file will silently fail if no files exists, so check here.
def zipFile = file("${buildDir}/outputs/distribution/realm-java-jni-libs-unstripped-${currentVersion}.zip")
if (!zipFile.exists()) {
throw new GradleException("Could not locate unstripped binary zip file in: ${zipFile.getPath()}")
}
exec {
commandLine 's3cmd', "--access_key=${s3AccessKey}", "--secret_key=${s3SecretKey}", 'put', zipFile.getAbsolutePath(), 's3://static.realm.io/downloads/java/'
}
}
}
task uploadUpdateVersion(type: Exec) {
group = 'Release'
description = 'Update the file on S3 containing the latest version'
def s3AccessKey = "${ -> getPropertyValueOrThrow('REALM_S3_ACCESS_KEY')}"
def s3SecretKey = "${ -> getPropertyValueOrThrow('REALM_S3_SECRET_KEY')}"
commandLine 's3cmd', "--access_key=${s3AccessKey}", "--secret_key=${s3SecretKey}", 'put', "${rootDir}/version.txt", 's3://static.realm.io/update/java'
}
task distribute {
group = 'Release'
description = 'Distribute release artifacts to S3'
dependsOn uploadDistributionPackage
dependsOn uploadUpdateVersion
}
task mavenCentralRealm(type: GradleBuild) {
description = 'Publish the Realm AAR and AP to Maven Central'
group = 'Publishing'
buildFile = file('realm/build.gradle')
tasks = ['publishToSonatype']
startParameter.projectProperties = gradle.startParameter.projectProperties
configure copyProperties
}
task mavenCentralAnnotations(type: GradleBuild) {
description = 'Publish the Realm Annotations to Maven Central'
group = 'Publishing'
buildFile = file('realm-annotations/build.gradle')
tasks = ['publishToSonatype']
startParameter.projectProperties = gradle.startParameter.projectProperties
configure copyProperties
}
task mavenCentralGradlePlugin(type: GradleBuild) {
description = 'Publish the Realm Gradle Plugin to Maven Central'
group = 'Publishing'
buildFile = file('gradle-plugin/build.gradle')
tasks = ['publishToSonatype']
startParameter.projectProperties = gradle.startParameter.projectProperties
configure copyProperties
}
task mavenCentralTransformer(type: GradleBuild) {
description = 'Publish the Realm Transformer to Maven Central'
group = 'Publishing'
buildFile = file('realm-transformer/build.gradle')
tasks = ['publishToSonatype']
startParameter.projectProperties = gradle.startParameter.projectProperties
configure copyProperties
}
task mavenCentralUpload {
description = 'Publish all the Realm artifacts to Maven Central'
group = 'Publishing'
dependsOn mavenCentralRealm
dependsOn mavenCentralAnnotations
dependsOn mavenCentralGradlePlugin
dependsOn mavenCentralTransformer
}