forked from linkedin/venice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
825 lines (727 loc) · 28.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
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
import com.github.spotbugs.snom.SpotBugsTask
import org.gradle.internal.logging.text.StyledTextOutput.Style
import org.gradle.internal.logging.text.StyledTextOutputFactory
import java.nio.file.Files
plugins {
id 'idea'
id 'java'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.12.0'
id 'com.dorongold.task-tree' version '2.1.0'
id 'com.github.johnrengelman.shadow' version '6.1.0' apply false
id 'com.github.spotbugs' version '4.8.0' apply false
id 'org.gradle.test-retry' version '1.5.0' apply false
id 'com.form.diff-coverage' version '0.9.5' apply false
id 'me.champeau.jmh' version '0.6.7' apply false
id 'io.github.lhotari.gradle-nar-plugin' version '0.5.1' apply false
id 'com.google.protobuf' version '0.9.3' apply false
}
apply from: "$rootDir/gradle/helper/git.gradle"
apply from: "$rootDir/gradle/helper/publishing.gradle"
/*
* This snippet allows the Gradle environment to be overridden with custom
* settings. This is useful in environments (such as a private company) where a
* third party wishes to use custom repositories, or inject certain
* functionality into the default Gradle build lifecycle.
*/
if (project.hasProperty('overrideBuildEnvironment')) {
apply from: file(project.overrideBuildEnvironment)
product {
codeQuality {
ignoreFailures = true
}
}
}
def avroVersion = '1.10.2'
def avroUtilVersion = '0.3.21'
def grpcVersion = '1.49.2'
// N.B.: The build should also work when substituting Kafka from the Apache fork to LinkedIn's fork:
def kafkaGroup = 'org.apache.kafka' // 'com.linkedin.kafka'
def kafkaVersion = '2.4.1' // '2.4.1.65'
def log4j2Version = '2.17.1'
def pegasusVersion = '29.31.0'
def protobufVersion = '3.21.7'
def jacksonVersion = '2.13.4'
def pulsarGroup = 'org.apache.pulsar'
def pulsarVersion = '2.10.3'
def alpnAgentVersion = '2.0.10'
def hadoopVersion = '2.10.2'
def apacheSparkVersion = '3.3.3'
def antlrVersion = '4.8'
def scala = '2.12'
ext.libraries = [
alpnAgent: "org.mortbay.jetty.alpn:jetty-alpn-agent:${alpnAgentVersion}",
antlr4: "org.antlr:antlr4:${antlrVersion}",
antlr4Runtime: "org.antlr:antlr4-runtime:${antlrVersion}",
apacheSparkAvro: "org.apache.spark:spark-avro_${scala}:${apacheSparkVersion}",
apacheSparkCore: "org.apache.spark:spark-core_${scala}:${apacheSparkVersion}",
apacheSparkSql: "org.apache.spark:spark-sql_${scala}:${apacheSparkVersion}",
avro: "org.apache.avro:avro:${avroVersion}",
avroCompiler: "org.apache.avro:avro-compiler:${avroVersion}",
avroMapred: "org.apache.avro:avro-mapred:${avroVersion}",
avroUtilBuilder: "com.linkedin.avroutil1:builder:${avroUtilVersion}",
avroUtilCompatHelper: "com.linkedin.avroutil1:helper-all:${avroUtilVersion}",
avroUtilFastserde: "com.linkedin.avroutil1:avro-fastserde:${avroUtilVersion}",
avroUtilSpotbugsPlugin: 'com.linkedin.avroutil1:spotbugs-plugin:0.2.69',
bouncyCastle: 'org.bouncycastle:bcprov-jdk15on:1.55',
bouncyCastleBcpkix: 'org.bouncycastle:bcpkix-jdk15on:1.55',
caffeine: 'com.github.ben-manes.caffeine:caffeine:2.8.5',
classgraph: 'io.github.classgraph:classgraph:4.8.60',
commonsCodec: 'commons-codec:commons-codec:1.4',
commonsConfiguration: 'commons-configuration:commons-configuration:1.9',
commonsIo: 'commons-io:commons-io:2.11.0',
commonsCli: 'commons-cli:commons-cli:1.5.0',
commonsLang: 'commons-lang:commons-lang:2.6',
conscrypt: 'org.conscrypt:conscrypt-openjdk-uber:2.5.2',
d2: "com.linkedin.pegasus:d2:${pegasusVersion}",
failsafe: 'net.jodah:failsafe:2.4.0',
fastUtil: 'it.unimi.dsi:fastutil:8.3.0',
grpcNettyShaded: "io.grpc:grpc-netty-shaded:${grpcVersion}",
grpcProtobuf: "io.grpc:grpc-protobuf:${grpcVersion}",
grpcServices: "io.grpc:grpc-services:${grpcVersion}",
grpcStub: "io.grpc:grpc-stub:${grpcVersion}",
hadoopCommon: "org.apache.hadoop:hadoop-common:${hadoopVersion}",
hadoopHdfs: "org.apache.hadoop:hadoop-hdfs:${hadoopVersion}",
httpAsyncClient: 'org.apache.httpcomponents:httpasyncclient:4.1.5',
httpClient5: 'org.apache.httpcomponents.client5:httpclient5:5.3',
httpCore5: 'org.apache.httpcomponents.core5:httpcore5:5.2.4',
httpCore5H2: 'org.apache.httpcomponents.core5:httpcore5-h2:5.2.4',
httpClient: 'org.apache.httpcomponents:httpclient:4.5.14',
httpCore: 'org.apache.httpcomponents:httpcore:4.4.16',
jacksonCore: "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}",
jacksonAnnotations: "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}",
jacksonDatabind: "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}",
javax: 'javax.servlet:javax.servlet-api:3.1.0',
javaxActivation: 'com.sun.activation:javax.activation:1.2.0',
jdom: 'org.jdom:jdom:1.1',
jna: 'net.java.dev.jna:jna:4.5.1',
jsr305: 'com.google.code.findbugs:jsr305:3.0.2',
joptSimple: 'net.sf.jopt-simple:jopt-simple:3.2',
kafka: "${kafkaGroup}:kafka_${scala}:${kafkaVersion}",
kafkaClients: "${kafkaGroup}:kafka-clients:${kafkaVersion}",
kafkaClientsTest: "${kafkaGroup}:kafka-clients:${kafkaVersion}:test",
log4j2api: "org.apache.logging.log4j:log4j-api:${log4j2Version}",
log4j2core: "org.apache.logging.log4j:log4j-core:${log4j2Version}",
log4j2Slf4j: "org.apache.logging.log4j:log4j-slf4j-impl:${log4j2Version}",
mail: 'javax.mail:mail:1.4.4',
mapreduceClientCore: "org.apache.hadoop:hadoop-mapreduce-client-core:${hadoopVersion}",
mapreduceClientJobClient: "org.apache.hadoop:hadoop-mapreduce-client-jobclient:${hadoopVersion}",
mockito: 'org.mockito:mockito-core:4.11.0',
netty: 'io.netty:netty-all:4.1.74.Final',
oss: 'org.sonatype.oss:oss-parent:7',
pulsarClient: "${pulsarGroup}:pulsar-client:${pulsarVersion}",
pulsarIoCore: "${pulsarGroup}:pulsar-io-core:${pulsarVersion}",
pulsarIoCommon: "${pulsarGroup}:pulsar-io-common:${pulsarVersion}",
r2: "com.linkedin.pegasus:r2:${pegasusVersion}",
restliCommon: "com.linkedin.pegasus:restli-common:${pegasusVersion}",
rocksdbjni: 'org.rocksdb:rocksdbjni:8.8.1',
samzaApi: 'org.apache.samza:samza-api:1.5.1',
slf4j: 'org.slf4j:slf4j:1.7.36',
slf4jApi: 'org.slf4j:slf4j-api:1.7.36',
slf4jSimple: 'org.slf4j:slf4j-simple:1.7.36',
snappy: 'org.iq80.snappy:snappy:0.4',
spark: 'com.sparkjava:spark-core:2.9.4', // Spark-Java Rest framework
spotbugs: 'com.github.spotbugs:spotbugs:4.5.2',
tehuti: 'io.tehuti:tehuti:0.12.3',
testcontainers: 'org.testcontainers:testcontainers:1.18.0',
testng: 'org.testng:testng:6.14.3',
tomcatAnnotations: 'org.apache.tomcat:annotations-api:6.0.53',
// Resolves java.lang.UnsupportedOperationException: setXIncludeAware is not supported on this JAXP implementation
// or earlier: class org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
xalan: 'xalan:xalan:2.7.1',
xerces: 'xerces:xercesImpl:2.9.1',
zkclient: 'com.101tec:zkclient:0.7', // For Kafka AdminUtils
zookeeper: 'org.apache.zookeeper:zookeeper:3.6.3',
zstd: 'com.github.luben:zstd-jni:1.5.2-3',
]
group = 'com.linkedin.venice'
publishing {
repositories {
mavenLocal()
maven {
name 'LinkedInJFrog'
url 'https://linkedin.jfrog.io/artifactory/venice'
if (System.getenv('JFROG_USERNAME') != null && System.getenv('JFROG_API_KEY') != null) {
credentials {
username System.getenv('JFROG_USERNAME')
password System.getenv('JFROG_API_KEY')
}
}
}
}
}
def parser = new XmlSlurper()
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
configurations {
alpnAgent {
}
}
dependencies {
alpnAgent libraries.alpnAgent
}
subprojects {
//apply group and version to all submodules
group = rootProject.group
version = rootProject.version
def isLeafSubModule = project.childProjects.isEmpty()
apply {
plugin 'idea'
plugin 'java-library'
plugin 'com.github.spotbugs'
plugin 'org.gradle.test-retry'
}
if (isLeafSubModule) {
apply {
plugin 'jacoco'
plugin 'com.form.diff-coverage'
plugin 'com.google.protobuf'
}
}
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
tasks.withType(JavaCompile) {
// Compiler arguments can be injected here...
// options.compilerArgs << '-Xlint:unchecked'
options.release = 8
}
}
java {
withSourcesJar()
// TODO: Enable after we have valid javadocs
//withJavadocJar()
}
if (isLeafSubModule) {
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:' + protobufVersion
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:' + grpcVersion
}
}
generateProtoTasks {
ofSourceSet('main')*.plugins {
grpc {}
}
}
}
}
configurations {
implementation {
// These are global exclusions that will apply to the entire project
exclude group: 'backport-util-concurrent'
exclude group: 'com.intellij.annotations'
exclude group: 'com.linkedin.avro-schemas'
exclude group: 'com.linkedin.container'
exclude group: 'com.linkedin.container-core'
exclude group: 'com.linkedin.security'
exclude group: 'com.linkedin.dds-storage-core'
exclude group: 'com.linkedin.linkedin-kafka-clients'
exclude group: 'com.linkedin.util', module: 'util-sql'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude module: 'clojure'
exclude module: 'kafka_2.10' // This ends up getting pulled in by a few dependencies, unfortunately :/ ...
exclude module: 'kafka_2.11'
}
compileOnly {
// These dependencies are transitively used at runtime, so we cannot exclude them further than compileOnly
exclude group: 'com.typesafe.scala-logging'
exclude group: 'log4j'
exclude group: 'org.slf4j'
}
all {
resolutionStrategy.force libraries.zookeeper
}
avroCompiler {
}
}
dependencies {
testImplementation libraries.log4j2api
testImplementation libraries.mockito
testImplementation libraries.testng
// Test utils and framework for all unit tests and integration tests.
testImplementation project(':internal:venice-test-common')
spotbugs libraries.spotbugs
spotbugsPlugins libraries.avroUtilSpotbugsPlugin
avroCompiler libraries.avroCompiler
avroCompiler libraries.avroUtilBuilder
avroCompiler 'org.slf4j:slf4j-simple:1.7.32'
implementation libraries.grpcNettyShaded
implementation libraries.grpcProtobuf
implementation libraries.grpcServices
implementation libraries.grpcStub
implementation 'org.ow2.asm:asm:9.7'
compileOnly libraries.tomcatAnnotations
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
task compileAvro(type: SourceTask) {
def sourceDir = file('src/main/resources/avro')
def outputDir = file("$buildDir/generated/sources/avro/java/main")
source sourceDir
inputs.files(configurations.avroCompiler).withNormalizer(ClasspathNormalizer)
outputs.dir(outputDir)
outputs.cacheIf { true }
doFirst {
def versionOverrides = [
// project(':internal:venice-common').file('src/main/resources/avro/StoreVersionState/v5', PathValidation.DIRECTORY)
]
def schemaDirs = [sourceDir]
sourceDir.eachDir { typeDir ->
def parseVersionId = { dir ->
(dir in versionOverrides) ? Integer.MAX_VALUE : dir?.name?.substring(1)?.toInteger()
}
def latestVersionDir = null
typeDir.eachDirMatch(~/v-?\d+/) { versionDir ->
if (parseVersionId(versionDir) > parseVersionId(latestVersionDir)) {
latestVersionDir = versionDir
}
}
if (latestVersionDir) {
schemaDirs << latestVersionDir
}
}
copy {
from (schemaDirs) {
include '*.avsc'
}
into temporaryDir
duplicatesStrategy = DuplicatesStrategy.FAIL
eachFile {
println "Copying avro schema ${relativePath(it.file)} ${it.file.parentFile in versionOverrides ? '(OVERRIDE)' : ''}"
}
}
javaexec {
classpath = configurations.avroCompiler
main = 'com.linkedin.avroutil1.builder.SchemaBuilder'
args = [
'--input', temporaryDir,
'--output', outputDir
]
}
}
}
sourceSets.main.java.srcDir(compileAvro)
tasks.withType(SpotBugsTask) {
effort = 'max'
reportLevel = 'low'
includeFilter = file(
project.hasProperty('spotallbugs') ?
"$rootDir/gradle/spotbugs/include-all.xml" :
"$rootDir/gradle/spotbugs/include.xml"
)
excludeFilter = file("$rootDir/gradle/spotbugs/exclude.xml")
ignoreFailures = project.hasProperty('spotbugs.ignoreFailures')
showStackTraces = false
reports ({
xml {
enabled = project.hasProperty('spotbugs.xml')
}
html {
enabled = !reports.getByName('XML').enabled
stylesheet = 'fancy-hist.xsl'
}
})
doFirst {
sourceDirs += sourceSets.getByName(baseName).output.generatedSourcesDirs
def generatedSources = sourceDirs.sum { dir ->
dir.path =~ "^$buildDir/generated/sources/" ?
fileTree(dir: dir, include: '**/*.java').collect { dir.relativePath(it) } : []
}
if (generatedSources) {
def generatedClasses = generatedSources*.replaceFirst('.java$', '').sum {
[ it + '.class', it + '\$*.class' ]
}
classes = classDirs.asFileTree.matching { exclude generatedClasses }
auxClassPaths += classDirs.asFileTree.matching { include generatedClasses }.each {
// Muted to reduce noise, but can be uncommented to debug exclusions
// println "Excluding generated class ${project.relativePath(it)}"
}
}
}
}
def ALPINI_TEST_FILTER = 'com.linkedin.alpini.*'
def ALPINI_NETTY_TEST_FILTER = 'io.netty.*'
def ALPINI_UNIT_TEST_TASK_NAME = 'alpiniUnitTest'
def ALPINI_FUNCTIONAL_TEST_TASK_NAME = 'alpiniFunctionalTest'
tasks.withType(Test) {
mustRunAfter tasks.withType(SpotBugsTask)
// For Spark to run on Java 17
jvmArgs "-XX:+IgnoreUnrecognizedVMOptions"
jvmArgs "--add-opens=java.base/java.nio=ALL-UNNAMED"
jvmArgs "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"
jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED"
jvmArgs "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED"
jvmArgs "--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED"
if (JavaVersion.current() == JavaVersion.VERSION_11) {
jvmArgs "-Dio.netty.tryReflectionSetAccessible=true"
}
forkEvery = Integer.valueOf(System.getProperty('forkEvery', '0'))
maxParallelForks = Integer.valueOf(System.getProperty('maxParallelForks', '4'))
minHeapSize = System.getProperty('minHeapSize', '1g')
maxHeapSize = System.getProperty('maxHeapSize', '4g')
systemProperty 'pubSubBrokerFactory', System.getProperty('pubSubBrokerFactory', "com.linkedin.venice.integration.utils.KafkaBrokerFactory")
System.getProperty('jvmArgs')?.eachMatch(/(?:[^\s'"]+|'[^']*'|"[^"]*")+/) { jvmArgs it }
doFirst {
println "forkEvery=$forkEvery"
println "maxParallelForks=$maxParallelForks"
println "jvmArgs=$allJvmArgs"
}
if (name != ALPINI_UNIT_TEST_TASK_NAME && name != ALPINI_FUNCTIONAL_TEST_TASK_NAME) {
filter {
excludeTestsMatching ALPINI_TEST_FILTER
excludeTestsMatching ALPINI_NETTY_TEST_FILTER
failOnNoMatchingTests = false
}
}
useTestNG {
excludeGroups 'flaky'
listeners = ['com.linkedin.venice.testng.VeniceSuiteListener', 'com.linkedin.venice.testng.VeniceTestListener']
}
retry {
maxRetries = 4 // 5 attempts in total
maxFailures = 100
failOnPassedAfterRetry = false
}
testLogging {
events = [] // N.B. we suppress all events as everything is taken care of in beforeTest and afterTest
showStandardStreams = false // to mute the DDS Router's noisy behavior...
exceptionFormat = 'full'
}
beforeTest { descriptor ->
def out = services.get(StyledTextOutputFactory).create("an-ouput")
out.style(Style.Normal).println("$descriptor.className > $descriptor.displayName STARTED")
}
afterTest { descriptor, result ->
def totalTime = result.endTime - result.startTime
def prettyTime = totalTime < 1000 ? "$totalTime ms" : "${totalTime / 1000} s"
def out = services.get(StyledTextOutputFactory).create("an-ouput")
def style = result.resultType == TestResult.ResultType.SUCCESS
? Style.Identifier
: result.resultType == TestResult.ResultType.FAILURE
? Style.Failure
: Style.Normal
def status = result.resultType == TestResult.ResultType.SUCCESS
? 'PASSED '
: result.resultType == TestResult.ResultType.FAILURE
? 'FAILED '
: 'SKIPPED '
out.style(Style.Normal).text("$descriptor.className > $descriptor.displayName ")
.style(style).text(status)
.style(Style.Normal).println("($prettyTime)")
if (result.resultType == TestResult.ResultType.FAILURE) {
def originalStacktrace = result.exception.getStackTrace()
ArrayList<StackTraceElement> truncatedStackTrace = []
for (int i = 0; i < originalStacktrace.length; i++) {
def element = originalStacktrace[i]
def className = element.getClassName()
if (i > 1 && (className.startsWith('org.gradle') || className.startsWith('jdk.internal'))) {
break
}
truncatedStackTrace[i] = element
}
def truncatedException = result.exception
truncatedException.setStackTrace(truncatedStackTrace.toArray(new StackTraceElement[0]))
out.text(' ').exception(truncatedException)
}
}
}
if (isLeafSubModule) {
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.enabled = true
html.enabled = true
}
doLast {
parseJacocoXml("$buildDir/reports/jacoco/test/jacocoTestReport.xml")
}
}
afterEvaluate {
jacocoTestCoverageVerification {
dependsOn jacocoTestReport
violationRules {
rule {
def threshold = project.ext.has('jacocoCoverageThreshold') ? project.ext.jacocoCoverageThreshold : 0.6
limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = threshold
}
}
}
}
diffCoverageReport {
diffSource.file = createDiffFile()
// Report locates at <module_name>/build/reports/jacoco/diffCoverage/html/index.html
reports {
html = true
xml = true
}
violationRules {
minBranches = project.ext.has('diffCoverageThreshold') ? project.ext.diffCoverageThreshold : 0.45
failOnViolation = true
}
}
task logCoverage {
doLast {
parseJacocoXml("$buildDir/reports/jacoco/test/jacocoTestReport.xml")
parseJacocoXml("$buildDir/reports/jacoco/diffCoverage/report.xml")
}
}
diffCoverage.dependsOn jacocoTestReport
diffCoverage.finalizedBy logCoverage
}
}
task flakyTest(type: Test) {
useTestNG {
includeGroups 'flaky'
}
}
task "$ALPINI_UNIT_TEST_TASK_NAME"(type: Test) {
useTestNG() {
includeGroups 'unit'
}
filter {
includeTestsMatching ALPINI_TEST_FILTER
includeTestsMatching ALPINI_NETTY_TEST_FILTER
failOnNoMatchingTests = false
}
}
task "$ALPINI_FUNCTIONAL_TEST_TASK_NAME"(type: Test) {
useTestNG() {
includeGroups 'functional'
}
filter {
includeTestsMatching ALPINI_TEST_FILTER
includeTestsMatching ALPINI_NETTY_TEST_FILTER
failOnNoMatchingTests = false
}
}
tasks.withType(Jar) {
zip64 = true
duplicatesStrategy = DuplicatesStrategy.FAIL
exclude('**/*.xml')
}
task testJar(type: Jar) {
classifier 'tests'
from sourceSets.test.output
}
// Only publish artifacts for projects that are at the leaf level
if (isLeafSubModule) {
publishing.configureArtifactPublishing(project, testJar)
}
}
task aggregateJavadoc(type: Javadoc) {
source subprojects.collect { project ->
project.sourceSets.main.allJava
}
classpath = files(subprojects.collect { project ->
project.sourceSets.main.compileClasspath
})
// generate javadoc with no warnings
getOptions().addStringOption('Xdoclint:none', '-quiet')
destinationDir = new File(buildDir, 'javadoc')
}
spotless {
ratchetFrom "${git.getUpstreamRemote()}/main"
java {
importOrder()
removeUnusedImports()
eclipse().configFile("$rootDir/gradle/spotless/eclipse-java-formatter.xml")
target '**/*.java'
targetExclude '**/generated/**'
}
}
task setupWorkspace {
println 'Setting up default git config'
def gitConfig = [
'core.hooksPath' : 'gradle/githooks',
'blame.ignoreRevsFile' : '.git-blame-ignore-revs',
'branch.autoSetupMerge' : 'true', // Only track remote branches
'branch.autoSetupRebase' : 'always',
'pull.rebase' : 'true',
]
gitConfig.each(git.setConfig)
}
task spotbugs {
dependsOn subprojects.tasks*.withType(SpotBugsTask)
}
check.dependsOn(spotbugs)
test {
mustRunAfter spotbugs
dependsOn subprojects.test
afterTest { descriptor, result ->
def totalTime = result.endTime - result.startTime
println "Total time of $descriptor.name was $totalTime"
}
}
assemble {
dependsOn (
setupWorkspace,
testClasses,
'internal:venice-test-common:jmhClasses',
'internal:venice-test-common:integrationTestClasses'
)
}
build {
dependsOn (
'services:venice-router:installDist',
'services:venice-server:installDist',
'services:venice-controller:installDist'
)
}
idea.project.ipr {
withXml { provider ->
provider.node.component
.find { it.@name == 'VcsDirectoryMappings' }
.mapping.@vcs = 'Git'
def inspectionProjectProfileManager = provider.node.component
.find { it.@name == 'InspectionProjectProfileManager' }
def danglingJavaDocInspectionProperties = [
class: "DanglingJavadoc",
enabled: "false",
level: "WARNING",
enabled_by_default: "false"
]
if (inspectionProjectProfileManager == null) {
inspectionProjectProfileManager = provider.node.appendNode(
"component",
[
name: "InspectionProjectProfileManager"
]
)
def profile = inspectionProjectProfileManager.appendNode(
"profile",
[
version: "1.0"
]
)
profile.appendNode(
"option",
[
name: "myName",
value: "Project Default"
]
)
profile.appendNode(
"inspection_tool",
danglingJavaDocInspectionProperties
)
inspectionProjectProfileManager.appendNode(
"version",
[
value: "1.0"
]
)
} else {
def danglingJavaDoc = inspectionProjectProfileManager.profile.inspection_tool
.find { it.@class == 'DanglingJavadoc' }
if (danglingJavaDoc == null) {
inspectionProjectProfileManager.profile.get(0).appendNode(
"inspection_tool",
danglingJavaDocInspectionProperties
)
} else {
danglingJavaDoc.@enabled = false
danglingJavaDoc.@level = "WARNING"
danglingJavaDoc.@enabled_by_default = false
}
}
}
}
// Allow running diffCoverage against uncommitted files
// See https://github.com/form-com/diff-coverage-gradle/issues/73
ext.createDiffFile = { ->
// Files that we don't plan to write unit tests for now. Will be worked in the future
def exclusionFilter = [
// Keep this sorted
// da-vinci-client
':!clients/da-vinci-client/src/main/java/com/linkedin/davinci/DaVinciBackend.java',
':!clients/da-vinci-client/src/main/java/com/linkedin/davinci/ingestion/isolated/IsolatedIngestionServer.java',
':!clients/da-vinci-client/src/main/java/com/linkedin/davinci/stats/ingestion/heartbeat/HeartbeatStatReporter.java',
// venice-client
':!clients/venice-client/src/main/java/com/linkedin/venice/fastclient/factory/ClientFactory.java',
// unit test for gRPC Transport Client is not straightforward, adding to exclusion list for now
':!clients/venice-client/src/main/java/com/linkedin/venice/fastclient/transport/GrpcTransportClient.java',
// unit test for deprecated DispatchingVsonStoreClient is not meaningful since most logic is in its parent class
':!clients/venice-client/src/main/java/com/linkedin/venice/fastclient/DispatchingVsonStoreClient.java',
// venice-producer
':!clients/venice-producer/src/main/java/com/linkedin/venice/producer/online/OnlineProducerFactory.java',
':!clients/venice-producer/src/main/java/com/linkedin/venice/producer/online/ProducerTool.java',
// venice-common
':!internal/venice-common/src/main/java/com/linkedin/venice/controllerapi/ControllerClient.java',
':!internal/venice-common/src/main/java/com/linkedin/venice/acl/handler/StoreAclHandler.java',
// venice-test-common
':!internal/venice-test-common/*',
// venice-controller
':!services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceController.java',
':!services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceControllerService.java',
':!services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceHelixAdmin.java',
':!services/venice-controller/src/main/java/com/linkedin/venice/controller/VeniceParentHelixAdmin.java',
// venice-router
':!services/venice-router/src/main/java/com/linkedin/venice/router/RouterServer.java',
':!services/venice-router/src/main/java/com/linkedin/venice/router/streaming/VeniceChunkedResponse.java',
':!services/venice-router/src/main/java/com/linkedin/venice/router/api/VeniceDispatcher.java',
// venice-server
':!services/venice-server/src/main/java/com/linkedin/venice/server/VeniceServer.java',
':!services/venice-server/src/main/java/com/linkedin/venice/listener/StatsHandler.java',
// venice-standalone
':!services/venice-standalone/*', // exclude the entire standalone project
// admin-tool
':!clients/venice-admin-tool/*',
// Keep this last
// Other files that have tests but are not executed in the regular unit test task
':!internal/alpini/*'
]
def file = Files.createTempFile(URLEncoder.encode(project.name, 'UTF-8'), '.diff').toFile()
def diffBase = "${git.getUpstreamRemote()}/main"
def command = [
'git', 'diff', "${diffBase}...", '--no-color', '--minimal', '--', '.'
]
command.addAll(exclusionFilter)
file.withOutputStream { out ->
exec {
commandLine command
standardOutput = out
}
}
return file
}
// for a given xml jacoco report, parse it and print out the branch coverage
ext.parseJacocoXml = { filePath ->
println "Parsing Jacoco XML file at: ${filePath}"
try {
def jacocoReport = parser.parse(filePath).children()
def branchCoverage = jacocoReport.find { it.name() == 'counter' && it.@type == 'BRANCH' }
def branchCoverageRatio = branchCoverage.@covered.toDouble() / (branchCoverage.@missed.toDouble() + branchCoverage.@covered.toDouble())
println "Branch coverage: ${(branchCoverageRatio * 100.0).round(2)}%"
} catch (Exception e) {
// failure to retrieve numbers should not fail the build
project.logger.debug("Branch coverage: N/A. There's either no branch coverage or " +
"the jacoco report is not generated.", e)
}
}
allprojects {
task printAllDependencies(type: DependencyReportTask) {}
}
def supportedJdkVersions = [JavaVersion.VERSION_1_8, JavaVersion.VERSION_11, JavaVersion.VERSION_17]
task verifyJdkVersion {
def currentJdkVersion = JavaVersion.current()
def isSupported = supportedJdkVersions.any {version -> currentJdkVersion.equals(version) }
if (!isSupported) {
throw new GradleException("Invalid JDK version: ${currentJdkVersion}.\n" + \
"Supported versions: ${supportedJdkVersions.join(', ')}.\n" + \
"Please set the JAVA_HOME environment variable to a supported version either locally or globally.")
}
println "JDK version ${currentJdkVersion} is valid."
}
gradle.taskGraph.whenReady {
// Ensure the JDK version is verified before any other tasks
verifyJdkVersion
}