-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
561 lines (491 loc) · 19.9 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
import org.springframework.boot.gradle.plugin.SpringBootPlugin
import java.text.SimpleDateFormat
/*
* Data Repository Building Notes
*
* USING SWAGGER-CODEGEN
* We use swagger-codegen to generate our model classes and controller interfaces with default methods.
* The swagger YAML file is the primary implementation and documentation of the Data Repository API.
*
* The gradle technique for running codegen as part of the build is written up here:
* https://blog.jcore.com/2017/05/22/automatically-generating-api-using-swagger-and-gradle/
* It relies on the behavior of the Java plugin, described here:
* https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_source_sets
*/
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('io.swagger.codegen.v3:swagger-codegen:3.0.63')
// Required for gradle liquibase plugin
classpath ('org.liquibase:liquibase-core:4.29.2')
}
}
plugins {
// This is set back to 3.4.2 because of: https://github.com/GoogleContainerTools/jib/issues/4265
id 'com.google.cloud.tools.jib' version '3.4.2'
id 'org.liquibase.gradle' version '3.0.1'
id 'org.gradle.test-retry' version '1.6.0'
id 'antlr'
id 'org.hidetake.swagger.generator' version '2.19.2'
id 'org.springframework.boot' version '3.3.5'
id 'idea'
id 'java'
id 'io.spring.dependency-management' version '1.1.6'
id 'jacoco'
// After merging a spotless version update which requires a large-scale code reformat, add the
// commit hash to .git-blame-ignore-revs to avoid cluttering git blame.
id 'com.diffplug.spotless' version '6.25.0' // SEE ABOVE.
id 'com.dorongold.task-tree' version '4.0.0'
// enables release info in sentry events
id 'com.gorylenko.gradle-git-properties' version '2.4.2'
id 'org.sonarqube' version '5.1.0.4882'
id 'com.srcclr.gradle' version '3.1.12'
}
allprojects {
group 'bio.terra'
version '2.182.0-SNAPSHOT'
ext {
resourceDir = "${rootDir}/src/main/resources/api"
}
// specifying versions for dependencies, not adding the dependencies themselves (yet)
apply plugin: "io.spring.dependency-management"
dependencyManagement {
imports {
mavenBom SpringBootPlugin.BOM_COORDINATES
}
dependencies {
dependency 'io.swagger.core.v3:swagger-annotations:2.2.25'
dependency 'io.swagger.codegen.v3:swagger-codegen-cli:3.0.63'
}
}
}
apply from: 'debug.gradle'
// skip subproject tasks by default when building jade-data-repo
subprojects.each { s ->
s.tasks.configureEach {
task -> task.enabled = (System.getenv("ENABLE_SUBPROJECT_TASKS") != null)
}
}
boolean isCiServer = System.getenv().containsKey("GITHUB_ACTIONS")
java {
sourceCompatibility = 17
targetCompatibility = 17
}
if (hasProperty('buildScan')) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
uploadInBackground = false
publishAlways()
def project = ""; def cluster = ""; def nschunk = ""
project = System.getenv("GOOGLE_CLOUD_PROJECT")
cluster = "jade-master-us-central1"
nschunk = ""
def startTest = new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC"))
buildFinished { ->
def endTest = new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC"))
link "Jump to StackDriver Logs 🔗 ", "https://console.cloud.google.com/logs/viewer?interval=CUSTOM&project=${project}&folder&organizationId&minLogLevel=0&expandAll=false&customFacets=&limitCustomFacetWidth=true&scrollTimestamp=${startTest}&dateRangeStart=${startTest}&dateRangeEnd=${endTest}&advancedFilter=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22${project}%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22${cluster}%22${nschunk}"
}
}
}
idea {
module {
downloadJavadoc = true
}
}
jacocoTestReport {
reports {
// sonarqube requires XML coverage output to upload coverage data
xml.required = true
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['bio/terra/grammar/**'])
}))
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = 0.1
}
}
}
}
check.dependsOn jacocoTestCoverageVerification
check.dependsOn jacocoTestReport
// If true, search local repository (~/.m2/repository/) first for dependencies.
def useMavenLocal = false
repositories {
if (useMavenLocal) {
mavenLocal() // must be listed first to take effect
}
mavenCentral()
maven {
url 'https://broadinstitute.jfrog.io/broadinstitute/libs-release-local/'
}
maven {
url 'https://broadinstitute.jfrog.io/broadinstitute/libs-snapshot-local/'
}
}
configurations {
generatedCompile
runtimeClasspath
}
dependencies {
implementation 'com.google.apis:google-api-services-serviceusage:v1-rev20230215-2.0.0'
implementation 'com.google.apis:google-api-services-appengine:v1-rev20230206-2.0.0'
implementation 'com.google.apis:google-api-services-oauth2:v2-rev20200213-2.0.0'
implementation 'com.google.apis:google-api-services-iam:v1-rev20230209-2.0.0'
implementation platform('com.google.cloud:libraries-bom:26.50.0')
implementation 'com.google.cloud:google-cloud-billing'
implementation 'com.google.cloud:google-cloud-resourcemanager'
implementation 'com.google.cloud:google-cloud-bigquery'
implementation 'com.google.cloud:google-cloud-storage'
implementation 'com.google.cloud:google-cloud-firestore'
implementation 'com.google.cloud:google-cloud-pubsub'
implementation 'com.google.cloud:spring-cloud-gcp-starter-logging:5.8.0'
implementation 'com.google.http-client:google-http-client'
implementation 'org.apache.commons:commons-compress:1.27.1' // For srcclr, jib plugin conflict
// More info: https://discuss.gradle.org/t/plugin-dependency-conflict-with-jib-and-srcclr/42355
implementation 'org.apache.commons:commons-dbcp2' // For database connection support
implementation 'org.apache.commons:commons-lang3'
implementation 'org.apache.commons:commons-collections4'
implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'
implementation 'org.apache.httpcomponents.client5:httpclient5'
implementation 'org.liquibase:liquibase-core'
implementation 'org.codehaus.janino:janino' // Provides if/else xml parsing for logback config
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'jakarta.validation:jakarta.validation-api'
implementation 'jakarta.annotation:jakarta.annotation-api'
implementation 'io.swagger.core.v3:swagger-annotations'
swaggerCodegen 'io.swagger.codegen.v3:swagger-codegen-cli'
implementation 'org.springframework:spring-jdbc'
implementation 'org.antlr:ST4:4.3.4' // String templating
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api'
implementation 'com.microsoft.sqlserver:mssql-jdbc:12.3.0.jre17-preview'
// For distributed locking of Spring @Scheduled tasks across multiple instances
implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:5.16.0'
implementation 'net.javacrumbs.shedlock:shedlock-spring:5.16.0'
implementation 'bio.terra:terra-common-lib:1.1.18-SNAPSHOT'
implementation 'org.broadinstitute.dsde.workbench:sam-client_2.13:v0.0.241'
implementation 'bio.terra:terra-policy-client:1.0.17-SNAPSHOT'
implementation 'bio.terra:terra-resource-buffer-client:0.198.42-SNAPSHOT'
implementation 'bio.terra:externalcreds-client-resttemplate:1.52.0-SNAPSHOT'
implementation 'org.glassfish.jersey.inject:jersey-hk2'
implementation 'com.squareup.okhttp3:okhttp'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'com.fasterxml.jackson.core:jackson-core'
implementation 'com.fasterxml.jackson.core:jackson-annotations'
implementation 'com.fasterxml.jackson.core:jackson-databind'
// Azure related dependencies
implementation 'com.azure:azure-identity:1.14.0'
implementation 'com.azure.resourcemanager:azure-resourcemanager:2.44.0'
implementation 'com.azure.resourcemanager:azure-resourcemanager-loganalytics:1.0.0'
implementation 'com.azure.resourcemanager:azure-resourcemanager-securityinsights:1.0.0-beta.5'
implementation 'com.azure:azure-storage-common:12.27.1'
implementation 'com.azure:azure-storage-file-datalake:12.21.0'
implementation 'com.azure:azure-data-tables:12.4.6'
implementation platform('io.sentry:sentry-bom:7.16.0') //import bom
implementation('io.sentry:sentry-spring-boot-starter-jakarta')
implementation('io.sentry:sentry-logback')
// OpenTelemetry @WithSpan annotations:
implementation 'io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations:2.8.0'
testImplementation 'org.apache.parquet:parquet-common:1.14.3'
testImplementation 'org.apache.parquet:parquet-hadoop:1.14.3'
testImplementation 'org.apache.parquet:parquet-hadoop-bundle:1.14.3'
testImplementation 'org.apache.parquet:parquet-encoding:1.14.3'
testImplementation 'org.apache.parquet:parquet-column:1.14.3'
testImplementation ('org.apache.hadoop:hadoop-common:3.4.1') {
exclude group: 'com.sun.jersey', module: 'jersey-core'
exclude group: 'com.sun.jersey', module: 'jersey-servlet'
exclude group: 'com.sun.jersey', module: 'jersey-json'
exclude group: 'com.sun.jersey', module: 'jersey-server'
exclude group: 'org.slf4j', module: 'slf4j-reload4j'
}
testImplementation('org.apache.hadoop:hadoop-mapreduce-client-core:3.4.1') {
exclude group: 'com.sun.jersey', module: 'jersey-core'
exclude group: 'com.sun.jersey', module: 'jersey-servlet'
exclude group: 'com.sun.jersey', module: 'jersey-json'
exclude group: 'com.sun.jersey', module: 'jersey-server'
exclude group: 'org.slf4j', module: 'slf4j-reload4j'
}
testImplementation 'au.com.dius.pact.provider:junit5:4.6.15'
testImplementation 'au.com.dius.pact.provider:junit5spring:4.6.15'
antlr 'org.antlr:antlr4:4.13.2'
liquibaseRuntime 'org.liquibase:liquibase-core'
liquibaseRuntime 'org.postgresql:postgresql'
liquibaseRuntime 'info.picocli:picocli:4.7.6'
testImplementation 'org.junit.vintage:junit-vintage-engine'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.zonky.test:embedded-database-spring-test:2.5.1'
testImplementation 'io.zonky.test:embedded-postgres:2.0.7'
implementation enforcedPlatform('io.zonky.test.postgres:embedded-postgres-binaries-bom:12.8.0')
generatedCompile 'org.springframework.boot:spring-boot-starter-web'
// boot-starter-validation required for jakarta.validation.Valid references, @Valid tags
generatedCompile 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.webjars:webjars-locator-core'
runtimeOnly 'org.webjars.npm:swagger-ui-dist:4.3.0'
generatedCompile 'io.swagger.core.v3:swagger-annotations'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
}
def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
swaggerSources {
server {
inputFile = file("${resourceDir}/data-repository-openapi.yaml")
code {
language = "spring"
library = "spring-boot"
outputDir = file("${buildDir}/generated-src/swagger")
components = ["models", "apis"]
rawOptions = [
"--invoker-package", "bio.terra",
"--api-package", "bio.terra.controller",
"--model-package", "bio.terra.model",
"-D", "interfaceOnly=true," +
"useTags=true," +
"dateLibrary=java8," +
"jakarta=true," +
// https://github.com/swagger-api/swagger-codegen-generators/pull/1308
"validationMode=legacy"
]
}
}
}
tasks.register('generateVersionFile') {
def properties = new Properties()
def versionFile = file "src/main/resources/version.properties"
properties.setProperty("semVer", project.getVersion().toString())
properties.setProperty("gitHash", getGitHash())
Writer writer = new FileWriter(versionFile, false)
properties.store(writer, "DO NOT EDIT. Autogenerated by build.gradle.")
writer.close()
}
generateGrammarSource {
arguments += ["-visitor", "-long-messages"]
}
tasks.register('unpack', Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
into("build/dependency")
}
def generatedOutputDir = 'src/generated/java'
clean.doFirst {
delete("${projectDir}/$generatedOutputDir")
delete("${rootDir}/datarepo-client/build")
delete("${rootDir}/datarepo-client/generated")
}
sourceSets {
generated {
compileClasspath = configurations.generatedCompile
}
main {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
test {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
}
jacoco {
toolVersion = '0.8.9'
}
sourceSets.main.java.srcDir "${buildDir}/generated-src/swagger"
bootRun {
classpath += sourceSets.generated.output
}
jar {
from sourceSets.generated.output
}
jib {
extraDirectories {
mkdir 'build/gen-expanded'
paths = ['build/gen-expanded']
}
from {
image = "us.gcr.io/broad-dsp-gcr-public/base/jre:17-debian"
}
to {
image = "gcr.io/broad-jade-dev/jade-data-repo:" + (System.env.GCR_TAG ?: getGitHash())
}
// Make sure that we disable remote lookups in message printing. See
// https://www.randori.com/blog/cve-2021-44228/
// for more information
container {
jvmFlags = ["-Xms1g", "-Xmx4g", "-Dlog4j2.formatMsgNoLookups=true"]
}
container.creationTime = buildTime()
}
static def buildTime() {
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'") // you can change it
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}
// jib expects all classes to be under app/classes in the resulting image. this, combined with the extraDirectories
// setting above will ensure that the generated classes end up in the right place when jib builds.
tasks.register('setupGeneratedDir', Copy) {
from file('build/classes/java/generated')
into file('build/gen-expanded/app/classes')
}
tasks.jib.dependsOn setupGeneratedDir
liquibase {
activities {
datarepo {
changelogFile project.ext.dbDatarepoChangesetFile
url project.ext.dbDatarepoUri
username project.ext.dbDatarepoUsername
password project.ext.dbDatarepoPassword
logLevel 'info'
}
// This is setup only to run "dropAll", not commands that require the changelog, like "update"
// To setup more functionality, see notes in this doc:
// https://docs.google.com/document/d/1hxT7ZOAY4MKPhjoLLZNJE4IB_3WncsDDYEg8m1myL-I/edit?usp=sharing
stairway {
url project.ext.dbStairwayUri
username project.ext.dbStairwayUsername
password project.ext.dbStairwayPassword
logLevel 'info'
}
}
}
spotless {
java {
target project.fileTree(project.rootDir) {
include 'src/**/*.java'
}
googleJavaFormat()
}
}
// -- Test tasks --
// The default 'test' task runs all of the unit tests.
// There are separate tasks for running just the unit tests and just the connected tests.
// connected tests and running all of the tests.
tasks.withType(Test).configureEach {
systemProperty 'spring.profiles.include', 'human-readable-logging'
}
test {
useJUnitPlatform {
includeTags 'bio.terra.common.category.Unit'
}
outputs.upToDateWhen { false }
maxParallelForks = 2
}
tasks.register('testConnected', Test) {
useJUnitPlatform {
includeTags 'bio.terra.common.category.Connected'
}
testLogging {
events = ["passed", "failed", "skipped", "started", "standard_out"]
}
retry {
if (isCiServer) {
maxRetries = 3
maxFailures = 15
}
}
maxParallelForks = 4
outputs.upToDateWhen { false }
maxHeapSize = "2g"
}
tasks.register('testIntegration', Test) {
useJUnitPlatform {
includeTags 'bio.terra.common.category.Integration'
}
testLogging {
events = ["passed", "failed", "skipped", "started", "standard_out"]
}
retry {
if (isCiServer) {
maxRetries = 3
maxFailures = 15
}
}
maxParallelForks = 8
outputs.upToDateWhen { false }
}
tasks.register('testUnit', Test) {
useJUnitPlatform {
includeTags 'bio.terra.common.category.Unit'
}
maxParallelForks = 2
outputs.upToDateWhen { false }
}
tasks.register('testOnDemand', Test) {
useJUnitPlatform {
includeTags 'bio.terra.common.category.OnDemand'
}
testLogging {
events = ["passed", "failed", "skipped", "started", "standard_out"]
}
outputs.upToDateWhen { false }
}
tasks.register('testAll', Test) {
useJUnitPlatform {
// Note: explicitly not including OnDemand tests
includeTags 'bio.terra.common.category.Connected', 'bio.terra.common.category.Unit'
}
outputs.upToDateWhen { false }
}
tasks.register('verifyPacts', Test) {
useJUnitPlatform {
includeTags 'bio.terra.common.category.Pact'
}
testLogging {
events = ["passed", "failed", "skipped", "started", "standard_out"]
}
outputs.upToDateWhen { false }
if (isCiServer) {
systemProperty 'pact.verifier.publishResults', true
}
// to run a local pactbroker, see:
// https://broadworkbench.atlassian.net/wiki/spaces/IRT/pages/2829680649/Contract+Test+Local+Development
if (System.getenv().containsKey('PACT_BROKER_URL')) {
systemProperty 'pactbroker.url', System.getenv('PACT_BROKER_URL')
}
systemProperty 'pactbroker.auth.username', System.getenv('PACT_BROKER_USERNAME')
systemProperty 'pactbroker.auth.password', System.getenv('PACT_BROKER_PASSWORD')
systemProperty 'pact.provider.version', System.getenv('PACT_PROVIDER_VERSION')
systemProperty 'pact.provider.branch', System.getenv('PACT_PROVIDER_BRANCH')
}
compileGeneratedJava.dependsOn swaggerSources.server.code
compileGeneratedJava.dependsOn generateGrammarSource
classes.dependsOn generatedClasses
compileJava.dependsOn compileGeneratedJava
ideaModule.dependsOn swaggerSources.server.code
idea.module.sourceDirs += file("$buildDir/generated-src/swagger/src/main/java")
// Run spotless check when running in github actions, otherwise run spotless apply.
compileJava {
if (isCiServer) {
dependsOn(spotlessCheck)
} else {
dependsOn(spotlessApply)
}
// UnauthenticatedApiController expects the version.properties file to be present at runtime
dependsOn(generateVersionFile)
}
sonar {
properties {
property "sonar.projectKey", "DataBiosphere_jade-data-repo"
property "sonar.projectName", "jade-data-repo"
property "sonar.organization", "broad-databiosphere"
property "sonar.host.url", "https://sonarcloud.io"
}
}