forked from DataBiosphere/jade-data-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
371 lines (324 loc) · 12.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
/*
* 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
*/
import io.swagger.codegen.config.CodegenConfigurator
import io.swagger.codegen.DefaultGenerator
buildscript {
ext {
springBootVersion = '2.1.7.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.swagger:swagger-codegen:2.4.11')
classpath('gradle.plugin.com.srcclr:gradle:3.1.0')
}
}
plugins {
id "com.google.cloud.tools.jib" version "1.6.1"
id 'org.liquibase.gradle' version '2.0.1'
id 'antlr'
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'antlr'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'jacoco'
apply plugin:'com.srcclr.gradle'
if (hasProperty('buildScan')) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
def project = ""; def cluster = ""; def nschunk = "";
if (System.getenv("NAMESPACEINUSE")) {
project = "broad-jade-integration"
cluster = "integration-master"
def ns = System.getenv("NAMESPACEINUSE")
nschunk = "%0Aresource.labels.namespace_name%3D%22${ns}%22%0Alabels.k8s-pod%2Fcomponent%3D%22${ns}-jade-datarepo-api%22"
} else {
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}"
}
}
}
tasks.withType(FindBugs) {
reports {
xml.enabled false
html.enabled true
html.stylesheet resources.text.fromFile('config/findbugs/plain.xsl')
}
}
tasks.withType(JacocoReport) {
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = 0.2
}
}
}
}
check.dependsOn jacocoTestCoverageVerification
group 'bio.terra'
version '0.1'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
url 'https://broadinstitute.jfrog.io/broadinstitute/libs-release-local/'
}
maven {
url 'https://broadinstitute.jfrog.io/broadinstitute/libs-snapshot-local/'
}
}
configurations {
generatedCompile
runtimeClasspath
}
// Exclude the Spring logger, so everything will use SLF4J
configurations.all {
exclude group: "commons-logging", module: "commons-logging"
}
dependencies {
// TODO: Unpack the "starter" and include just what we use
compile 'ch.qos.logback:logback-classic:1.2.3' // Logger
compile 'com.google.apis:google-api-services-cloudbilling:v1-rev20200106-1.30.3'
compile 'com.google.apis:google-api-services-cloudresourcemanager:v1-rev549-1.25.0'
compile 'com.google.apis:google-api-services-serviceusage:v1beta1-rev206-1.25.0'
compile 'com.google.cloud:google-cloud-bigquery:1.108.1'
compile 'com.google.cloud:google-cloud-storage:1.108.0'
compile 'com.google.cloud:google-cloud-firestore:1.22.0'
compile group: 'com.google.cloud', name: 'google-cloud-pubsub', version: '1.104.1'
compile 'io.springfox:springfox-swagger-ui:2.10.0'
compile 'io.springfox:springfox-swagger2:2.9.2'
compile 'org.apache.commons:commons-dbcp2:2.7.0' // For database connection support
compile 'org.apache.commons:commons-lang3:3.9'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'org.liquibase:liquibase-core:3.8.0' // For upgrade
compile 'org.postgresql:postgresql:42.2.8' // Postgres jdbc driver
compile 'org.slf4j:slf4j-api:1.7.28' // Logging facade
compile "org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE"
compile 'org.springframework:spring-jdbc:5.1.9.RELEASE'
compile 'org.broadinstitute.dsde.workbench:sam-client_2.12:0.1-9435410-SNAP'
compile 'org.antlr:ST4:4.3' // String templating
compile group: 'io.kubernetes', name: 'client-java', version: '8.0.2'
// This allows you to build with a local Stairway JAR file, instead of the one from the repository
// For example, ./gradlew -Pstairwayjar=/Users/dd/code/stairway/build/libs/stairway-0.0.4-SNAPSHOT.jar
// Or define the environment variable ORG_GRADLE_PROJECT_stairwayjar
if (project.hasProperty("stairwayjar")) {
implementation files(project.ext.get("stairwayjar"))
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
} else {
implementation 'bio.terra:stairway:0.0.21-SNAPSHOT'
}
// Forcing this due to vulnerability issues
compile ('com.fasterxml.jackson.core:jackson-databind:2.11.0.rc1') {
force = true
}
compile ('com.fasterxml.jackson.core:jackson-core:2.10.2') {
force = true
}
antlr "org.antlr:antlr4:4.8"
// Need groovy on the class path for the logback config. Could use XML and skip this dependency,
// but the groovy config is... well... groovy.
runtime group: 'org.codehaus.groovy', name: 'groovy', version: '2.5.7'
// Findbugs annotations, so we can selectively suppress findbugs findings
compileOnly 'com.google.code.findbugs:annotations:3.0.1'
liquibaseRuntime 'org.liquibase:liquibase-core:3.8.0'
liquibaseRuntime 'org.postgresql:postgresql:42.2.7'
liquibaseRuntime 'ch.qos.logback:logback-classic:1.2.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile 'org.postgresql:postgresql:42.2.8'
testCompile 'com.google.code.findbugs:annotations:3.0.1'
generatedCompile 'org.springframework.boot:spring-boot-starter-web'
generatedCompile 'io.springfox:springfox-swagger2:2.7.0'
generatedCompile 'io.springfox:springfox-swagger-ui:2.7.0'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}
def openapiSourceFile = 'src/main/resources/data-repository-openapi.yaml'
def generatedOutputDir = 'src/generated/java'
task generateApi {
// specify the task inputs and outputs so gradle knows what to rebuild based on what has changed
inputs.file("$projectDir/$openapiSourceFile")
outputs.dir("$projectDir/$generatedOutputDir")
doLast {
def config = new CodegenConfigurator()
config.setInputSpec("file:///$projectDir/$openapiSourceFile")
config.setOutputDir("$projectDir")
config.setLang('spring')
// These properties are not well documented. The only way I've found to figure them out is to
// locally install the swagger-codegen tool and invoke it to get the specific help for the
// spring boot options.
config.setAdditionalProperties([
'interfaceOnly' : 'true', // only generate the model and API interfaces
'useTags' : 'true', // organize the swagger ui page by tags
'library' : 'spring-boot', // do spring-boot code generation
'dateLibrary' : 'java8', // do java8 code generation
'apiPackage' : 'bio.terra.controller',
'modelPackage' : 'bio.terra.model',
'invokerPackage': 'bio.terra',
'sourceFolder' : generatedOutputDir
])
new DefaultGenerator().opts(config.toClientOptInput()).generate()
}
}
generateGrammarSource {
arguments += ["-visitor", "-long-messages"]
}
task unpack(type: Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
into("build/dependency")
}
clean.doFirst {
delete("${projectDir}/$generatedOutputDir")
}
def excludePattern = 'generated-src/antlr/main/bio/terra/grammar/'
def excludeGrammarPattern = '${buildDir}/' + excludePattern + '*'
tasks.withType(Checkstyle) {
exclude excludeGrammarPattern
exclude "${buildDir}/generated-src/antlr/main/bio/terra/grammar/*"
}
sourceSets {
generated {
compileClasspath = configurations.generatedCompile
}
main {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
test {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
checkstyle {
toolVersion '7.8.1'
checkstyleGenerated.enabled = false // Don't check generated code
configFile file("config/checkstyle/checkstyle.xml")
}
findbugs {
toolVersion '3.0.1'
ignoreFailures = false
excludeFilter = file("config/findbugs/excludeFilter.xml")
reportsDir = file("$project.buildDir/reports/findbugs")
effort = "max"
}
jacoco {
toolVersion '0.8.2'
}
}
bootRun {
classpath += sourceSets.generated.output
}
jar {
from sourceSets.generated.output
}
def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
jib {
extraDirectories.paths = ['build/gen-expanded']
to {
image = "gcr.io/broad-jade-dev/jade-data-repo:"+(System.env.GCR_TAG ?: getGitHash())
}
}
// 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.
task setupGeneratedDir(type: 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 'debug'
}
}
}
// -- 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.
test {
useJUnit {
includeCategories 'bio.terra.common.category.Unit'
}
outputs.upToDateWhen { false }
}
task testConnected(type: Test) {
useJUnit {
includeCategories 'bio.terra.common.category.Connected'
}
testLogging {
events = ["passed", "failed", "skipped", "started", "standard_out"]
}
outputs.upToDateWhen { false }
}
task testIntegration(type: Test) {
useJUnit {
includeCategories 'bio.terra.common.category.Integration'
}
testLogging {
events = ["passed", "failed", "skipped", "started", "standard_out"]
}
outputs.upToDateWhen { false }
}
task testUnit(type: Test) {
useJUnit {
includeCategories 'bio.terra.common.category.Unit'
}
outputs.upToDateWhen { false }
}
task testAll(type: Test) {
useJUnit {
includeCategories 'bio.terra.common.category.Connected', 'bio.terra.common.category.Unit'
}
outputs.upToDateWhen { false }
}
compileGeneratedJava.dependsOn generateApi
compileGeneratedJava.dependsOn generateGrammarSource
classes.dependsOn generatedClasses
compileJava.dependsOn compileGeneratedJava
ideaModule.dependsOn generateApi