-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.gradle
More file actions
854 lines (711 loc) · 28.1 KB
/
Copy pathbuild.gradle
File metadata and controls
854 lines (711 loc) · 28.1 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
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
//
// 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.
//
// Please try to keep this build file as similar to the other family build files
// as is possible.
//
import com.github.spotbugs.snom.SpotBugsTask
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.attributes.java.TargetJvmEnvironment
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import java.util.regex.Pattern
// ----------------------------------------------------------------
// Plugins
// ----------------------------------------------------------------
plugins {
id 'java-library'
id 'kotlin'
id 'cpp'
id 'java-library-distribution'
id 'checkstyle'
id 'pmd'
id 'com.github.spotbugs'
id 'maven-publish'
id 'jacoco'
// handy plugin for discovering task dependencies
// id "com.dorongold.task-tree" version "2.1.0"
}
// ----------------------------------------------------------------
// Constants
// ----------------------------------------------------------------
ext {
JAVA_HOME = org.gradle.internal.jvm.Jvm.current().javaHome
JAVA_INCLUDE = "${JAVA_HOME}/include"
CBL_GROUP = 'com.couchbase.lite'
JAR_ARTIFACT = 'couchbase-lite-java'
ZIP_ARTIFACT = 'couchbase-lite-java-community'
CBL_DESCRIPTION = 'Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine.'
CBL_LICENSE = 'Couchbase, Inc. Community Edition License Agreement'
CBL_NOTICES_FILE = "notices.txt"
CBL_LICENSE_FILE = "LICENSE_community.txt"
CBL_LICENSE_URL = "https://raw.githubusercontent.com/couchbase/product-texts/${getLicenseVersion()}/mobile/couchbase-lite/license/${CBL_LICENSE_FILE}"
CBL_PROJECT_URL = 'https://github.com:couchbase/couchbase-lite-java-ce-root'
CBL_ISSUES_URL = 'https://github.com/couchbase/couchbase-lite-java-ce-root/issues'
CBL_SITE_URL = 'https://developer.couchbase.com/mobile/'
BUILD_TIME = Instant.now().toString()
BUILD_RELEASE = file("${ROOT_DIR}/version.txt").text.trim()
BUILD_NUMBER = (project.hasProperty("buildNumber") && buildNumber) ? buildNumber : "SNAPSHOT"
BUILD_VERSION = "${BUILD_RELEASE}-${BUILD_NUMBER}"
BUILD_COMMIT = getBuildId()
CBL_LICENSE_DIR = "${ROOT_DIR}/legal/mobile/couchbase-lite/license"
CBL_COMMON_ROOT_DIR = "${ROOT_DIR}/common"
CBL_COMMON_DIR = "${CBL_COMMON_ROOT_DIR}/common"
CBL_COMMON_JAVA_DIR = "${CBL_COMMON_ROOT_DIR}/java"
CBL_CE_ROOT_DIR = "${ROOT_DIR}/ce"
CBL_CE_COMMON_DIR = "${CBL_CE_ROOT_DIR}/common"
GENERATED_DIR = "${buildDir}/generated/sources"
REPORTS_DIR = "${buildDir}/reports"
ETC_DIR = "${CBL_COMMON_ROOT_DIR}/etc"
CBL_CORE_NATIVE_DIR = "${CBL_COMMON_ROOT_DIR}/lite-core"
CBL_NATIVE_DIR = "${buildDir}/native"
CBL_JNI_INCLUDE_DIR = "${GENERATED_DIR}/include"
DEPENDENCIES = ['okio', 'okhttp']
OKHTTP_VERSION = '4.11.0' //'3.14.7'
SPOTBUGS_VERSION = '4.7.3'
}
// Build platform
def PLATFORM = "???"
if (OperatingSystem.current().isMacOsX()) { PLATFORM = "macos" }
else if (OperatingSystem.current().isWindows()) { PLATFORM = "windows" }
else if (OperatingSystem.current().isLinux()) { PLATFORM = "linux" }
// Comma separated list of annotations for tests that should not be run.
// e.g., -PtestFilter='com.couchbase.lite.internal.utils.SlowTest,com.couchbase.lite.internal.utils.VerySlowTest'
def TEST_FILTER = (!project.hasProperty("testFilter")) ? null : testFilter.replaceAll("\\s", "")
// Target repo for maven publish
def MAVEN_URL = (!project.hasProperty("mavenUrl")) ? null : mavenUrl
// Set -Pverbose to get full console logs for tests
def VERBOSE = project.hasProperty("verbose")
// Set true to enable coverage
// The incantation for generating a coverage report is:
// ./gradlew -Pcoverage coverage
def COVERAGE = project.hasProperty("coverage")
// ----------------------------------------------------------------
// Build
// ----------------------------------------------------------------
group = CBL_GROUP
version = BUILD_VERSION
compileJava.options.encoding = "UTF-8"
java {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
sourceSets {
main {
java.srcDirs = [
"${CBL_COMMON_DIR}/main/java", // Common
"${CBL_COMMON_JAVA_DIR}/main/java", // Common Java
"${CBL_CE_COMMON_DIR}/main/java", // CE Common
"src/main/java",
"${GENERATED_DIR}/java",
]
resources.srcDirs = [
"${CBL_COMMON_JAVA_DIR}/main/resources", // Resource files
CBL_NATIVE_DIR, // Native Libraries
]
}
test {
java.srcDirs = [
"${CBL_COMMON_DIR}/test/java", // Common tests
"${CBL_COMMON_JAVA_DIR}/test/java", // Common Java tests
"${CBL_CE_COMMON_DIR}/test/java", // CE Common tests
]
resources.srcDirs = [
"${CBL_COMMON_DIR}/test/assets", // Common test assets
]
}
}
}
repositories {
google()
mavenCentral()
}
dependencies {
compileOnly 'androidx.annotation:annotation:1.3.0'
compileOnly "com.github.spotbugs:spotbugs-annotations:${SPOTBUGS_VERSION}"
implementation "com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}"
testCompileOnly 'androidx.annotation:annotation:1.3.0'
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:${KOTLIN_VERSION}"
testImplementation 'junit:junit:4.13.2'
}
// Copy the version template into the source, inserting build info
task generateCBLVersion(type: Copy) {
outputs.upToDateWhen { false }
from("${CBL_COMMON_JAVA_DIR}/templates/CBLVersion.java") {
filter(
ReplaceTokens,
tokens: [
VERSION: BUILD_VERSION.toString(),
VARIANT: 'CE',
TYPE : 'release',
BUILD : BUILD_NUMBER.toString(),
COMMIT : BUILD_COMMIT.toString()])
}
into "${GENERATED_DIR}/java/com/couchbase/lite/internal/core"
}
project.afterEvaluate {
sourcesJar.dependsOn generateCBLVersion
compileJava.dependsOn generateCBLVersion
compileKotlin.dependsOn generateCBLVersion
}
// ----------------------------------------------------------------
// Build Native
// ----------------------------------------------------------------
// For generating JNI headers:
compileJava.options.compilerArgs += ["-h", CBL_JNI_INCLUDE_DIR]
// Native Components:
model {
platforms {
osx {
architecture "x86_64"
operatingSystem "osx"
}
windows {
architecture "x86_64"
operatingSystem "windows"
}
linux {
architecture "x86_64"
operatingSystem "linux"
}
}
toolChains {
visualCpp(VisualCpp)
clang(Clang)
gcc(Gcc)
}
repositories {
libs(PrebuiltLibraries) {
liteCore {
binaries.withType(SharedLibraryBinary) {
def os = targetPlatform.operatingSystem
if (os.macOsX) {
headers.srcDir file("${CBL_CORE_NATIVE_DIR}/macos/x86_64/include")
sharedLibraryFile = file("${CBL_CORE_NATIVE_DIR}/macos/x86_64/lib/libLiteCore.dylib")
}
else if (os.windows) {
headers.srcDir file("${CBL_CORE_NATIVE_DIR}/windows/x86_64/include")
sharedLibraryFile = file("${CBL_CORE_NATIVE_DIR}/windows/x86_64/lib/LiteCore.dll")
sharedLibraryLinkFile = file("${CBL_CORE_NATIVE_DIR}/windows/x86_64/lib/LiteCore.lib")
}
else if (os.linux) {
headers.srcDir file("${CBL_CORE_NATIVE_DIR}/linux/x86_64/include")
sharedLibraryFile = file("${CBL_CORE_NATIVE_DIR}/linux/x86_64/lib/libLiteCore.so")
}
}
}
}
}
components {
LiteCoreJNI(NativeLibrarySpec) {
if (PLATFORM == "macos") { targetPlatform "osx" }
else { targetPlatform PLATFORM }
sources {
cpp {
source {
srcDir "${CBL_COMMON_DIR}/main/cpp"
include "**/*.cc"
}
lib library: 'liteCore', linkage: 'shared'
}
}
binaries.withType(StaticLibraryBinarySpec) { buildable = false }
binaries.withType(SharedLibraryBinarySpec) { binary ->
setupJNILibraryBuildTasks(binary.sharedLibraryFile, targetPlatform)
}
binaries.all {
if (targetPlatform.operatingSystem.macOsX) {
cppCompiler.args '-I', CBL_JNI_INCLUDE_DIR
cppCompiler.args '-I', JAVA_INCLUDE
cppCompiler.args '-I', "${JAVA_INCLUDE}/darwin"
cppCompiler.args '-std=c++17'
cppCompiler.args '-stdlib=libc++'
linker.args '-stdlib=libc++'
}
else if (targetPlatform.operatingSystem.windows) {
cppCompiler.args "-I${CBL_JNI_INCLUDE_DIR}"
cppCompiler.args "-I${JAVA_INCLUDE}"
cppCompiler.args "-I${JAVA_INCLUDE}/win32"
cppCompiler.args '/MD'
cppCompiler.args '/EHsc'
cppCompiler.args '/wd4068'
cppCompiler.args '/std:c++17'
}
else if (targetPlatform.operatingSystem.linux) {
cppCompiler.args '-I', CBL_JNI_INCLUDE_DIR
cppCompiler.args '-I', JAVA_INCLUDE
cppCompiler.args '-I', "${JAVA_INCLUDE}/linux"
cppCompiler.args '-std=c++17'
}
}
}
}
}
// ----------------------------------------------------------------
// Javadoc
// ----------------------------------------------------------------
javadoc {
failOnError false
exclude "**/internal/**"
exclude "com/couchbase/lite/utils"
options {
title = "${CBL_LICENSE} ${BUILD_VERSION}"
memberLevel = JavadocMemberLevel.PUBLIC
docEncoding = 'UTF-8'
encoding = 'UTF-8'
charSet = 'UTF-8'
locale = 'en_US'
links "https://docs.oracle.com/javase/8/docs/api/"
addStringOption('Xdoclint:none', '-quiet')
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_8) > 0) {
addStringOption("-release", "8")
addBooleanOption('-ignore-source-errors', true)
}
}
}
// ----------------------------------------------------------------
// Static analysis
// ----------------------------------------------------------------
def FILE_FILTER = ['**/gen/**', "okhttp3/**", "org/json/**"]
/////// Checkstyle
checkstyle {
toolVersion = "8.42"
dependencies {
checkstyle "com.puppycrawl.tools:checkstyle:${toolVersion}"
checkstyle "com.github.sevntu-checkstyle:sevntu-checks:1.39.0"
checkstyle fileTree(dir: "${ETC_DIR}/checkstyle", include: ['kotlin-checks-0.9.jar'])
}
configFile = file("${ETC_DIR}/checkstyle/checkstyle.xml")
configProperties = ['configDir': file("${ETC_DIR}/checkstyle")]
showViolations true
}
task checkstyle(type: Checkstyle) {
description 'Checkstyle'
group 'verification'
afterEvaluate { dependsOn generateCBLVersion }
source sourceSets.main.java.srcDirs
include '**/*.java'
exclude FILE_FILTER
classpath = files()
reports {
xml {
enabled = true
outputLocation = file("${REPORTS_DIR}/checkstyle.xml")
}
html {
enabled = true
outputLocation = file("${REPORTS_DIR}/checkstyle.html")
}
}
}
/////// PMD
pmd {
toolVersion '6.26.0'
ruleSets = []
}
task pmd(type: Pmd) {
description 'PMD'
group 'verification'
afterEvaluate { dependsOn generateCBLVersion }
ruleSetFiles = files("${ETC_DIR}/pmd/pmd.xml")
source = sourceSets.main.java.srcDirs
include '**/*.java'
exclude FILE_FILTER
reports {
xml {
enabled = true
outputLocation = file("${REPORTS_DIR}/pmd.xml")
}
html {
enabled = true
outputLocation = file("${REPORTS_DIR}/pmd.html")
}
}
}
/////// SpotBugs
// If SpotBug is run on code generated with Java 11
// it will generate quite a few extraneous NULLCHECK warnings.
// Sadly the problem is Java 11 code generation: the only solution
// is to disable the check.
spotbugs { toolVersion = SPOTBUGS_VERSION }
['Html', 'Xml'].each { reportType ->
task("spotbugs${reportType}", type: SpotBugsTask) {
description "Spotbugs with ${reportType} report"
group 'verification'
dependsOn compileJava, processResources
effort = "max"
reportLevel = "medium"
ignoreFailures = false
sourceDirs = project.files(sourceSets.main.java.srcDirs)
classDirs = fileTree(dir: "${buildDir}/classes/java/main")
def classpaths = []
tasks.withType(JavaCompile).each { task -> classpaths = task.classpath }
classpaths.each { dir -> auxClassPaths += project.files(dir) }
excludeFilter = file("${ETC_DIR}/spotbugs/spotbugs.xml")
onlyAnalyze = ['com.couchbase.lite.-']
reports {
xml {
required = (reportType == "Xml")
outputLocation = file("${REPORTS_DIR}//spotbugs.xml")
}
html {
required = (reportType == "Html")
outputLocation = file("${REPORTS_DIR}//spotbugs.html")
stylesheet = 'fancy-hist.xsl'
}
}
}
}
// ----------------------------------------------------------------
// Testing
// ----------------------------------------------------------------
compileTestJava.options.encoding = "UTF-8"
compileKotlin.kotlinOptions.jvmTarget = "1.8"
compileTestKotlin.kotlinOptions.jvmTarget = "1.8"
kotlin { kotlinDaemonJvmArgs = ["-Xmx3072m", "-Xms512m"] }
test {
jacoco { enabled = COVERAGE }
if (System.env.LD_LIBRARY_PATH != null) { jvmArgs "-Djava.library.path=${System.env.LD_LIBRARY_PATH}" }
workingDir = new File(workingDir, ".test-" + new Date().format('yyMMddHHmm'))
if (!workingDir.exists()) { workingDir.mkdirs() }
if (TEST_FILTER != null) { exclude TEST_FILTER }
testLogging {
outputs.upToDateWhen { false }
events = ["failed", "skipped"]
showStandardStreams = VERBOSE
showCauses = true
showExceptions = true
showStackTraces = true
exceptionFormat = 'full'
}
}
// ----------------------------------------------------------------
// Coverage
// ----------------------------------------------------------------
// The incantation for generating a coverage report is:
// ./gradlew -Pcoverage=true coverage
// The reason for this is that we want to be able to generate
// binaries that have not been instrumented and do not require
// the jacoco package when run
jacoco { toolVersion = JACOCO_VERSION }
jacocoTestReport {
afterEvaluate {
classDirectories.setFrom(classDirectories.files.collect { fileTree(dir: it, exclude: FILE_FILTER) })
if (COVERAGE) { test.finalizedBy jacocoTestReport }
}
reports {
xml.enabled true
html.enabled true
}
}
// ----------------------------------------------------------------
// Jar
// ----------------------------------------------------------------
jar { archivesBaseName = JAR_ARTIFACT }
// ----------------------------------------------------------------
// Distribution
// ----------------------------------------------------------------
distributions {
main {
distributionBaseName = ZIP_ARTIFACT
contents {
if (PLATFORM == "linux") {
into("support") {
from("${CBL_CORE_NATIVE_DIR}/linux//x86_64/lib")
// this depends on the copy following (not copying) symbolic links
include 'libgcc_s.so'
include 'libicudata.so.??'
include 'libicui18n.so.??'
include 'libicuuc.so.??'
include 'libstdc++.so.?'
exclude '**/pkgconfig'
exclude '**/icu'
}
}
def license = fileTree(CBL_LICENSE_DIR)
license.include CBL_LICENSE_FILE
into("license") { from license }
def blackduck = fileTree("${projectDir}/..")
blackduck.include CBL_NOTICES_FILE
into(".") { from blackduck }
def javadoc = fileTree("${buildDir}/libs")
javadoc.include "*-javadoc.jar"
into("docs") { from javadoc }
include {
def name = it.name
// allow it if it is a directory,
// it is nested in a folder (name != path)
// it is our artifact
// it is the license
// it is an explicit dependency
return it.isDirectory() ||
(!name.equals(it.getPath())) ||
name.startsWith(JAR_ARTIFACT) ||
name.startsWith(CBL_LICENSE_FILE) ||
name.startsWith(CBL_NOTICES_FILE) ||
DEPENDENCIES.contains(name.split("-")[0])
}
// Move the main jar file into lib folder
// and remove the build numbers
eachFile {
def name = it.name
def path = it.path
if (name.endsWith("javadoc.jar")) {
it.name = "${JAR_ARTIFACT}-${BUILD_RELEASE}-javadoc.jar"
}
else if (name.startsWith(JAR_ARTIFACT) &&
name.endsWith(".jar") &&
(!path.contains("/lib/"))) {
it.name = "${JAR_ARTIFACT}-${BUILD_RELEASE}.jar"
it.path = path.replaceFirst("(${ZIP_ARTIFACT}[^/]+).+") { _, p -> "${p}/lib/${it.name}" }
}
}
}
}
}
// ----------------------------------------------------------------
// Publication
// ----------------------------------------------------------------
def mavenRepoUser = System.getenv('MAVEN_REPO_USR')
def mavenRepoPass = System.getenv('MAVEN_REPO_PSW')
// Generate javadoc.jar
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveBaseName = JAR_ARTIFACT
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
distZip.dependsOn javadocJar
distTar.dependsOn javadocJar
// Generate source.jar
task sourcesJar(type: Jar) {
archiveBaseName = JAR_ARTIFACT
archiveClassifier = 'sources'
from sourceSets.main.java.srcDirs
}
artifacts {
archives javadocJar
archives sourcesJar
}
project.afterEvaluate {
tasks.withType(Tar) { duplicatesStrategy = DuplicatesStrategy.EXCLUDE }
tasks.withType(Zip) { duplicatesStrategy = DuplicatesStrategy.EXCLUDE }
}
// Include Android variant definition in Gradle Module Metadata
def androidApiConfig = configurations.create("androidApi").tap {
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.LIBRARY))
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.class, TargetJvmEnvironment.ANDROID))
attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_API))
}
}
// Add variant artifact as a dependencies, since it's in another module
dependencies {
androidApi("com.couchbase.lite:couchbase-lite-android:$version")
}
def androidRuntimeConfig = configurations.create("androidRuntime").tap {
extendsFrom(androidApiConfig)
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.LIBRARY))
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.class, TargetJvmEnvironment.ANDROID))
attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_RUNTIME))
}
}
(components.java as AdhocComponentWithVariants).with {
addVariantsFromConfiguration(androidApiConfig) {
mapToMavenScope("compile")
mapToOptional()
}
addVariantsFromConfiguration(androidRuntimeConfig) {
mapToMavenScope("runtime")
mapToOptional()
}
}
publishing {
publications {
couchbaseLiteJava(MavenPublication) {
def suffix = (PLATFORM == "linux") ? "" : "-${PLATFORM}"
groupId CBL_GROUP
artifactId "${JAR_ARTIFACT}${suffix}"
version BUILD_VERSION
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = "${CBL_GROUP}:${JAR_ARTIFACT}"
description = CBL_DESCRIPTION
url = CBL_SITE_URL
licenses {
license {
name = CBL_LICENSE
url = CBL_LICENSE_URL
distribution = "repo"
}
}
developers {
developer {
name = "Couchbase Mobile"
email = "mobile@couchbase.com"
organization = "Couchbase"
organizationUrl = "https://www.couchbase.com"
}
}
issueManagement {
system = "github"
url = CBL_ISSUES_URL
}
scm {
url = CBL_SITE_URL
connection = CBL_PROJECT_URL
developerConnection = CBL_PROJECT_URL
}
withXml {
def dependencies = asNode().dependencies.dependency
// Include only configured dependencies
dependencies.each {
if (!DEPENDENCIES.contains(it.artifactId.last().value())) {
it.parent().remove(it)
}
}
}
}
}
}
repositories {
maven {
url MAVEN_URL
credentials {
username mavenRepoUser
password mavenRepoPass
}
allowInsecureProtocol = true
}
}
}
// ----------------------------------------------------------------
// Tasks
// ----------------------------------------------------------------
///////// Dev tasks
task smokeTest(dependsOn: ['clean', 'compileJava', 'checkstyle', 'pmd', 'spotbugsHtml', 'testClasses'])
task devTest(dependsOn: ['test'])
if (COVERAGE) { task coverage(dependsOn: ['test']) }
///////// CI tasks
task ciCheck(dependsOn: ['compileJava', 'checkstyle', 'pmd', 'spotbugsXml', 'testClasses'])
task ciBuild(dependsOn: ['assemble'])
task ciTest(dependsOn: ['test'])
task ciPublish(dependsOn: ['distZip', 'generatePomFileForCouchbaseLiteJavaPublication', 'publishCouchbaseLiteJavaPublicationToMavenRepository'])
// ordering (roughly last to first)
project.afterEvaluate {
tasks.withType(Javadoc) { shouldRunAfter test }
test.shouldRunAfter smokeTest
testClasses.shouldRunAfter tasks.withType(SpotBugsTask)
tasks.withType(SpotBugsTask) { shouldRunAfter tasks.withType(Pmd) }
tasks.withType(Pmd) { shouldRunAfter tasks.withType(Checkstyle) }
tasks.withType(Checkstyle) { shouldRunAfter compileJava }
}
// ----------------------------------------------------------------
// Extensions
// ----------------------------------------------------------------
def setupJNILibraryBuildTasks(library, platform) {
tasks.whenTaskAdded { task ->
if (task.name == "LiteCoreJNISharedLibrary") {
task.dependsOn(compileJava)
createCopyNativeLibraryTask(library, platform)
}
}
}
def createCopyNativeLibraryTask(library, targetPlatform) {
def libPath = "${CBL_NATIVE_DIR}/libs/${getNativeLibraryResourcePath(targetPlatform)}"
// Copy LiteCore libraries for any other platforms, if available
task copyLiteCore(type: Copy) { thisTask ->
from(CBL_CORE_NATIVE_DIR) {
exclude "**/include"
exclude "**/pkgconfig"
exclude "**/icu"
if (targetPlatform.operatingSystem.isMacOsX()) {
include "macos/x86_64/lib/libLiteCore.dylib"
}
else if (targetPlatform.operatingSystem.isWindows()) {
include "windows/x86_64/lib/LiteCore.dll"
}
// When building Linux, include everything
else if (targetPlatform.operatingSystem.isLinux()) {
include "linux/x86_64/lib/libLiteCore.so"
include "macos/x86_64/lib/libLiteCore.dylib"
include "macos/x86_64/lib/libLiteCore.dylib.MD5"
include "macos/x86_64/lib/libLiteCoreJNI.dylib"
include "macos/x86_64/lib/libLiteCoreJNI.dylib.MD5"
include "windows/x86_64/lib/LiteCore.dll"
include "windows/x86_64/lib/LiteCore.dll.MD5"
include "windows/x86_64/lib/LiteCoreJNI.dll"
include "windows/x86_64/lib/LiteCoreJNI.dll.MD5"
}
}
into "${CBL_NATIVE_DIR}/libs"
}
// Copy the JNI native library generated for this platform
task copyJni(type: Copy, dependsOn: "LiteCoreJNISharedLibrary") {
from library
into libPath
}
// Add MD5 signatures to both the JNI lib (copied by copyJni) and to
// LiteCore lib (copied by copyLiteCore) for this platform.
task signNativeLibs(dependsOn: ["copyJni", "copyLiteCore"]) { thisTask ->
doLast {
fileTree(dir: libPath).each { lib ->
def fPath= lib.getPath()
if (!(fPath.endsWith(".MD5") || new File("${fPath}.MD5").exists())) { ant.checksum(file: lib) }
}
}
}
processResources.dependsOn(["signNativeLibs"])
}
def getNativeLibraryResourcePath(platform) {
final path = "/x86_64/lib"
if (platform.operatingSystem.isMacOsX()) { return "macos${path}" }
else if (platform.operatingSystem.isWindows()) { return "windows${path}" }
else if (platform.operatingSystem.isLinux()) { return "linux${path}" }
else { return "${platform.operatingSystem.name}${path}" }
}
def getLicenseVersion() { return getCommit("product-texts", "master") }
def getBuildId() {
def hostname = "rogue"
try { hostname = "hostname".execute().text.trim() }
catch (Exception ignore) {}
return "${getCommit("couchbase-lite-java-ee-root", "unofficial").substring(0, 10)}@${hostname}"
}
def getCommit(project, dflt) {
def manifest = null
try {
manifest = new FileReader("${ROOT_DIR}/../manifest.xml")
def revEx = Pattern.compile("<project.* name=\"${project}\".* revision=\"([\\dabcdef]{40})\"")
def l
while ((l = manifest.readLine()) != null) {
def m = revEx.matcher(l)
if (m.find()) { return m.group(1) }
}
}
catch (Exception ignore) {}
finally {
if (manifest != null) {
try { manifest.close() }
catch (Exception ignore) {}
}
}
return dflt
}