This repository has been archived by the owner on Mar 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 207
/
build.gradle
462 lines (395 loc) · 14.3 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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
//
// build.gradle
//
// Copyright (c) 2017, 2018, 2019 Couchbase, Inc 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.
//
// The Module-level Build File
// NOTE: moved from project build.gradle to make CBL compilable as sub-module of application
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
apply plugin: 'com.github.kt3k.coveralls'
def homeDir = "${projectDir}/.."
def baseDir = "${homeDir}/.."
def etcDir = "${homeDir}/etc"
def libsDir = "${baseDir}/libs"
def sharedDir = "${baseDir}/shared"
def liteCore = "${libsDir}/couchbase-lite-core"
def reportsDir = "${buildDir}/reports"
/**
* group and version
*/
group = 'com.couchbase.lite'
version = file("${baseDir}/version.txt").text.trim()
// -PbuildNumber=123
def buildNo = "0"
if (hasProperty("buildNumber")) {
buildNo = buildNumber
}
// git commit hash
def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
// defining this property in the file ~/.gradle/gradle.properties
// can dramatically reduce your build time.
def buildAbis = null
if (hasProperty("targetAbis")) { buildAbis = targetAbis.split(',') }
/**
* The android block is where you configure all your Android-specific
* build options.
*/
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName version
project.archivesBaseName = "couchbase-lite-android-${versionName}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
if (buildAbis != null) { ndk { abiFilters buildAbis } }
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_static', "-DANDROID_TOOLCHAIN=clang", '-DANDROID_PLATFORM=android-19'
cppFlags "-std=c++11 -frtti -fexceptions -fPIC"
// explicitly build libs
targets 'LiteCoreJNI'
}
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "int", "BUILD_NO", "$buildNo"
buildConfigField "String", "GitHash", "\"${getGitHash()}\""
}
debug {
testCoverageEnabled = true
buildConfigField "int", "BUILD_NO", "$buildNo"
buildConfigField "String", "GitHash", "\"${getGitHash()}\""
}
}
externalNativeBuild {
cmake {
path "${sharedDir}/CMakeLists.txt"
}
}
sourceSets {
main {
java.srcDirs = [
"src/ce/java", // CE android specific codes
"src/main/java", // android specific codes
"${sharedDir}/src/main/java", // shared java codes
]
}
androidTest {
java.srcDirs = [
"src/androidTest/java", // android specific codes
"${sharedDir}/src/androidTest/java" // lite-core java codes
]
assets.srcDirs = [
"src/main/assets",
"src/androidTest/assets",
"${liteCore}/C/tests/data" // lite-core test assets
]
}
}
lintOptions {
disable 'InvalidPackage', 'UseSparseArrays', 'AuthLeak', 'BadHostnameVerifier'
abortOnError false
}
}
dependencies {
compileOnly 'com.android.support:support-annotations:28.0.0'
compileOnly 'com.google.code.findbugs:annotations:3.0.1'
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
// ----------------------------------------------------------------
// local.properties
// ----------------------------------------------------------------
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
// -- bintray
def bintrayUser = properties.getProperty('bintray.user')
def bintrayKey = properties.getProperty('bintray.key')
// -- maven repo
def mavenRepoUrl = properties.getProperty('maven.repo.url')
def mavenRepoUser = properties.getProperty('maven.repo.user')
def mavenRepoPass = properties.getProperty('maven.repo.pass')
// ----------------------------------------------------------------
// delete .externalNativeBuild to force rerun of cmake
// This is necessary because 'clean' deletes the file 'zconf.h'
// which is in .../build/intermediates, causing subsequent
// builds to fail.
// ----------------------------------------------------------------
clean.doFirst {
delete "${projectDir}/.externalNativeBuild"
}
// ----------------------------------------------------------------
// javadoc.jar and source.jar
// ----------------------------------------------------------------
// Generate source.jar
task sourcesJar(type: Jar) {
baseName = project.name
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
// Generate javadoc
task javadoc(type: Javadoc) {
failOnError false
source android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
options {
title = "Couchbase Lite ${project.version}"
memberLevel = JavadocMemberLevel.PUBLIC
docEncoding = 'UTF-8'
encoding = 'UTF-8'
charSet = 'UTF-8'
locale = 'en_US'
links "https://docs.oracle.com/javase/7/docs/api/"
linksOffline "https://developer.android.com/reference/", "${project.android.sdkDirectory}/docs/reference"
}
include 'com/couchbase/lite/*'
exclude '**/internal/**'
/* Turn off javadoc 8 overly pedantic lint checking */
if (JavaVersion.current().isJava8Compatible()) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
// Generate javadoc.jar
task javadocJar(type: Jar, dependsOn: javadoc) {
baseName = project.name
classifier = 'javadoc'
from javadoc.destinationDir
}
// ----------------------------------------------------------------
// Deployment
// ----------------------------------------------------------------
artifacts {
archives javadocJar
archives sourcesJar
}
def siteUrl = 'http://developer.couchbase.com/mobile/'
def gitUrl = 'https://github.com:couchbase/couchbase-lite-android.git'
// JFrog Bintray - JCenter deployment
bintray {
user = bintrayUser
key = bintrayKey
publications = ['mavenJava']
pkg {
repo = 'couchbase'
name = 'couchbase-lite-android'
desc = 'Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine.'
userOrg = 'couchbase'
licenses = ['Couchbase, Inc. Community Edition License Agreement']
labels = ['couchbase lite', 'android', 'sync', 'mobile']
vcsUrl = gitUrl
websiteUrl = siteUrl
issueTrackerUrl = 'https://github.com/couchbase/couchbase-lite-android/issues'
publicDownloadNumbers = false
version {
name = this.version
}
}
}
// -------------------------------------------------------------------------------------------------
// Maven Publishing
// https://docs.gradle.org/current/userguide/publishing_maven.html
// -------------------------------------------------------------------------------------------------
// Create the pom configuration:
def pomConfig = {
name "com.couchbase.lite:couchbase-lite-android"
description "Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine."
url "http://developer.couchbase.com/mobile/"
licenses {
license {
name "Couchbase, Inc. Community Edition License Agreement"
url "https://www.couchbase.com/binaries/content/assets/website/legal/ce-license-agreement.pdf"
distribution "repo"
}
}
developers {
developer {
name "Couchbase Mobile"
email "mobile@couchbase.com"
organization 'Couchbase'
organizationUrl 'http://www.couchbase.com'
}
}
issueManagement {
system 'github'
url 'https://github.com/couchbase/couchbase-lite-android/issues'
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
project.afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
groupId group
artifactId 'couchbase-lite-android'
version this.version
artifact bundleReleaseAar
artifact sourcesJar
artifact javadocJar
pom.withXml {
def root = asNode()
// Workaround for description:
root.appendNode('description', 'Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine.')
root.children().last() + pomConfig
// maven-publish workaround to include dependencies
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
publishing {
repositories {
maven {
credentials {
username mavenRepoUser
password mavenRepoPass
}
url mavenRepoUrl
}
}
}
// ----------------------------------------------------------------
// Static analysis
// ----------------------------------------------------------------
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', '**/gen/**', "okhttp3/**"]
apply plugin: 'checkstyle'
task checkstyle(type: Checkstyle) {
description 'Checkstyle'
group 'verification'
configFile file("${etcDir}/checkstyle/checkstyle.xml")
configProperties = ['configDir': file("${etcDir}/checkstyle")]
source android.sourceSets.main.java.srcDirs
include '**/*.java'
exclude fileFilter
classpath = files()
showViolations true
reports {
xml {
enabled = true
setDestination(file("${reportsDir}/checkstyle.xml"))
}
html {
enabled = true
setDestination(file("${reportsDir}/reports/checkstyle.html"))
}
}
}
apply plugin: 'pmd'
pmd { toolVersion "5.8.1" }
task pmd(type: Pmd) {
description 'PMD'
group 'verification'
ruleSetFiles = files("${etcDir}/pmd/pmd.xml")
source = android.sourceSets.main.java.srcDirs
include '**/*.java'
exclude fileFilter
reports {
xml {
enabled = true
setDestination(file("${reportsDir}/reports/pmd.xml"))
}
html {
enabled = true
setDestination(file("${reportsDir}/pmd.html"))
}
}
}
// !!FIXME: Update to SpotBugs
apply plugin: 'findbugs'
def findbugsAll = task('findbugs') {
description 'Findbugs with all reports'
group 'verification'
}
project.afterEvaluate {
['Html', 'Xml'].each { reportType ->
findbugsAll.dependsOn task("findbugs${reportType}", type: FindBugs) {
description "Findbugs with $reportType report"
group 'verification'
dependsOn tasks.find { t -> t.name.endsWith 'compileDebugSources' }
findbugs.toolVersion = "3.0.1"
effort = "max"
reportLevel = "medium"
ignoreFailures = false
source = android.sourceSets.main.java.srcDirs.collect {
dir -> fileTree(dir: dir, include: '**/*.java').getFiles()
}.flatten()
classes = fileTree(dir: "${buildDir}/intermediates/javac/debug/compileDebugJavaWithJavac/classes", excludes: fileFilter)
classpath = files()
excludeFilter = file("${etcDir}/findbugs/findbugs.xml")
reports {
xml {
enabled = (reportType == "Xml")
setDestination(file("${reportsDir}/findbugs.xml"))
}
html {
enabled = (reportType == "Html")
setDestination(file("${reportsDir}/findbugs.html"))
}
}
}
}
}
// ----------------------------------------------------------------
// Coveralls
// ----------------------------------------------------------------
coveralls {
jacocoReportPath = "${buildDir}/reports/coverage/debug/report.xml"
}
task smoketest(dependsOn: ['checkstyle', 'lint', 'findbugsHtml', 'pmd', 'testDebugUnitTest'])
task checkLocal(dependsOn: ['smoketest', 'connectedDebugAndroidTest'])
task buildCI(dependsOn: ['checkstyle', 'findbugsXml', 'pmd', 'check', 'connectedAndroidTest'])