forked from treasure-data/digdag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
668 lines (591 loc) · 23.6 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
plugins {
id 'com.github.johnrengelman.shadow' version '5.2.0'
id 'com.github.kt3k.coveralls' version '2.10.1'
id 'com.github.spotbugs' version '4.0.5'
id 'net.ltgt.apt-idea' version '0.21'
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'idea'
allprojects {
group = 'io.digdag'
version = '0.10.5-SNAPSHOT'
ext {
isSnapshotRelease = version.endsWith('-SNAPSHOT')
if (project.hasProperty("snapshotVersion")) {
if (isSnapshotRelease) {
project.version = project.version.replaceAll(/-SNAPSHOT$/, "-${project.snapshotVersion}")
}
else {
throw new GradleException("-PsnapshotVersion is set but current version is not -SNAPSHOT")
}
}
}
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'net.ltgt.apt-idea'
// 'maven' plugin is deprecated and replaced by 'maven-publish'.
// But it is required for task 'pom' which generates pom.xml in root and subproject root.
// ci/validate.sh call the task and run some mvn commands like 'enforcer'.
// But there is no enforcer rule definition. So it might be better to remove the task and the plugin.
apply plugin: 'maven'
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
jacoco {
toolVersion = '0.8.5'
}
}
subprojects {
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'com.github.spotbugs'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.25'
compile group: 'io.micrometer', name: 'micrometer-core', version: '1.2.0'
compile group: 'io.micrometer', name: 'micrometer-registry-jmx', version: '1.2.0'
compile(group: 'io.github.yoyama', name: 'fluency-meter-registory_2.12', version: '0.4.0') {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: 'org.msgpack', module: 'msgpack-core'
}
compileOnly "org.immutables:value:2.3.9:annotations"
testCompileOnly "org.immutables:value:2.3.9:annotations"
annotationProcessor "org.immutables:value:2.3.9"
testAnnotationProcessor "org.immutables:value:2.3.9"
testCompile 'junit:junit:4.13.2'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'pl.pragmatists:JUnitParams:1.0.5'
}
ext {
jacksonVersion = "2.9.10"
jacksonDatabindVersion = "2.9.10"
awsJavaSdkVersion = "1.11.686"
guavaVersion = "30.1.1-jre"
guiceVersion = "5.0.1"
}
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
spotbugs {
toolVersion = '4.0.1'
effort = 'max'
reportLevel = 'high'
ignoreFailures = true
excludeFilter = file("${rootProject.projectDir}/config/findbugs-exclude.xml")
}
spotbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
spotbugsTest {
reports {
xml.enabled = false
html.enabled = true
}
}
jacocoTestReport {
dependsOn test
reports {
xml.enabled = false
html.enabled = false
}
onlyIf = { true }
// exclude classes generated by Immutables
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/Immutable*'])
}))
executionData.setFrom(fileTree(buildDir).include("/jacoco/*.exec"))
}
}
test {
testLogging {
info.events = ["started", "passed", "skipped", "failed", "standardOut", "standardError"]
}
// Shard test classes over CI workers
if (System.env.CI_NODE_INDEX) {
def n = System.env.CI_NODE_TOTAL as Integer
def i = System.env.CI_NODE_INDEX as Integer
include {
// Recurse into all packages
if (it.file.isDirectory()) {
return true
}
// Include test class based on worker index
def included = Math.abs(it.file.hashCode()) % n == i
if (System.env.CI_DEBUG?.toBoolean()) {
logger.info("test '" + it.file + '" included: ' + included)
}
return included
}
}
doFirst {
// used by TemporaryDigdagServer
if (jacoco.enabled) {
def workingDir = getWorkingDir().getAbsolutePath().replaceAll("^[A-Z]:", '').replaceAll('\\\\', '/')
// Transform relative path to the jar to absolute path.
def jvmArg = jacoco.getAsJvmArg().replaceAll('javaagent:build', 'javaagent:' + workingDir + '/build')
logger.info("JACOCO_JVM_ARG:" + jvmArg)
environment "JACOCO_JVM_ARG", jvmArg
}
}
jacoco {
enabled = true
destinationFile = file("$buildDir/jacoco/${name}.exec")
excludes = ['**/Immutable*', '*Immutable*', 'generated/**']
}
}
javadoc {
options {
locale = 'en_US'
encoding = 'UTF-8'
}
}
task testsJar(type: Jar) {
archiveClassifier = 'tests'
from sourceSets.test.output
}
task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
}
task deps(type: DependencyReportTask) {
}
configurations {
testArtifacts.extendsFrom testRuntime
}
artifacts {
testArtifacts testsJar
}
def generateDependency = { String scope, xml, dep ->
def dependenciesNode = xml.dependencies[0] ?: xml.appendNode('dependencies')
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
if (scope != 'compile') {
dependencyNode.appendNode('scope', scope)
}
if (dep.targetConfiguration == 'testArtifacts') {
dependencyNode.appendNode('classifier', 'tests')
}
dep.excludeRules.each { ExcludeRule rule ->
// apply exclusions
def xmlExclusions = dependencyNode.exclusions[0] ?: dependencyNode.appendNode('exclusions')
def xmlExclusion = xmlExclusions.appendNode('exclusion')
xmlExclusion.appendNode('groupId', rule.group)
xmlExclusion.appendNode('artifactId', rule.module == null ? '*' : rule.module)
}
}
def pomXmlModifier = {
def xml = asNode()
// gradle somehow uses 'runtime' as the default scope but 'compile' is desired.
// gradle also makes transitive dependencies flat somehow but it's not desired.
// here recreates dependencies section.
xml.remove(xml.dependencies)
// configuration compile
configurations.compile.allDependencies.each(generateDependency.curry('compile', xml))
configurations.runtime.dependencies.each(generateDependency.curry('runtime', xml))
configurations.testCompile.dependencies.each(generateDependency.curry('test', xml))
configurations.testRuntime.dependencies.each(generateDependency.curry('test', xml))
configurations.annotationProcessor.dependencies.each(generateDependency.curry('provided', xml))
}
// Generate maven manifests for sub-modules
task pom {
doLast {
pom {
project {
parent {
groupId project.group
artifactId 'digdag'
version project.version
}
}
}
.withXml(pomXmlModifier)
.writeTo("${delegate.project.projectDir}/pom.xml")
}
}
// digdag-docs is out of target on publish
if (![project(":digdag-docs")].contains(project)) {
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
afterEvaluate {
artifact testsJar
artifact sourcesJar
artifact javadocJar
pom.withXml(pomXmlModifier)
}
pom { // https://central.sonatype.org/pages/requirements.html
name = "${project.name}"
afterEvaluate { project ->
description = "Digdag"
}
url = "https://www.digdag.io/"
licenses {
license {
// http://central.sonatype.org/pages/requirements.html#license-information
name = "The Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
name = "Sadayuki Furuhashi"
email = "[email protected]"
}
developer {
name = "Muga Nishizawa"
email = "[email protected]"
}
developer {
name = "Mitsunori Komatsu"
email = "[email protected]"
}
developer {
name = "You Yamagata"
email = "[email protected]"
}
developer {
name = "Shota Suzuki"
email = "[email protected]"
}
}
scm {
connection = "scm:git:git://github.com/treasure-data/digdag.git"
developerConnection = "scm:git:[email protected]:treasure-data/digdag.git"
url = "https://github.com/treasure-data/digdag"
}
}
}
}
repositories {
maven { // publishMavenJavaPublicationToMavenCentralRepository
name = "mavenCentral"
if (project.ext.isSnapshotRelease) {
url "https://oss.sonatype.org/content/repositories/snapshots"
} else {
url "https://oss.sonatype.org/service/local/staging/deploy/maven2"
}
credentials {
username = project.hasProperty("ossrhUsername") ? ossrhUsername : ""
password = project.hasProperty("ossrhPassword") ? ossrhPassword : ""
}
}
}
}
if (project.hasProperty('signing.gnupg.keyName')) {
signing {
useGpgCmd()
sign publishing.publications.mavenJava
}
}
}
}
jacocoTestReport {
dependsOn = subprojects.jacocoTestReport
reports {
xml.enabled = true
html.enabled = true
}
onlyIf = { true }
sourceDirectories.setFrom(files(subprojects.sourceSets.main.allSource.srcDirs.flatten()))
classDirectories.setFrom(files(subprojects.sourceSets.main.output.flatten()))
executionData.setFrom(subprojects.jacocoTestReport.executionData)
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/Immutable*'])
}))
}
}
check.dependsOn('jacocoTestReport')
coveralls {
sourceDirs += jacocoTestReport.sourceDirectories.toList()
}
wrapper {
// Find the latest version at https://gradle.org/releases/
gradleVersion = '6.8.3'
}
project(':digdag-ui') {
task dependenciesUi {
doFirst {
exec {
// npm ci requires npm version 5.7 or more.
commandLine System.env.NPM ?: "npm", "ci"
}
}
}
task buildUi {
inputs.files fileTree(dir: ".", include: ["*.js", "*.jsx", "*.ts", "*.tsx", "config/*"])
outputs.dir "public"
doFirst {
exec {
commandLine System.env.NPM ?: "npm", "run", "build"
environment "SHA", "assets"
}
}
dependsOn('dependenciesUi')
// include public/* in the jar file
processResources {
from '.'
include 'public/**/*'
}
processResources.dependsOn('buildUi')
}
task testUi {
doFirst {
exec {
commandLine System.env.NPM ?: "npm", "run", "test"
}
}
dependsOn('dependenciesUi')
}
test.dependsOn('testUi')
task checkUi {
doFirst {
exec {
commandLine System.env.NPM ?: "npm", "run", "lint"
}
exec {
commandLine System.env.NPM ?: "npm", "run", "type"
}
}
dependsOn('dependenciesUi')
}
check.dependsOn('checkUi')
}
project(':digdag-cli') {
apply plugin: 'com.github.johnrengelman.shadow'
// Include digdag-ui in the shadow jar which are not in the dependencies
// of digdag-cli but should be included.
configurations {
shadow {
extendsFrom runtime
}
}
if (!project.hasProperty("withoutUi")) {
dependencies {
shadow project(':digdag-ui')
}
shadowJar.dependsOn(project(':digdag-ui').jar)
}
shadowJar {
configurations = [project.configurations.shadow]
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor-Id': project.group,
'Specification-Title': project.name,
'Specification-Version': project.version,
'Main-Class': 'io.digdag.cli.Main'
}
mergeServiceFiles {
// this block is necessary to merge META-INF/services/* files.
// undertow is using ServiceLoader to find ExchangeAttributeBuilder
// which is used by access logger.
}
// force org.weakref.jmx to use unshaded guava to keep binary size small
exclude 'org/weakref/jmx/internal/guava/**/*'
relocate 'org.weakref.jmx.internal.guava', 'com.google.common'
}
task classpath(type: Copy, dependsOn: ['jar']) {
File dest = file("${rootProject.projectDir}/classpath")
doFirst { dest.deleteDir() }
from configurations.shadow + files("${project.libsDir}/${project.name}-${project.version}.jar")
into dest
}
}
def cliBuildFile = file("pkg/digdag-${project.version}.jar")
task cli(dependsOn: ':digdag-cli:shadowJar') {
doLast {
file('pkg').mkdirs()
cliBuildFile.write("")
cliBuildFile.append(file("digdag-cli/src/main/sh/selfrun.sh").readBytes())
cliBuildFile.append(file("digdag-cli/build/libs/digdag-cli-${project.version}-all.jar").readBytes())
cliBuildFile.setExecutable(true)
}
}
task classpath(dependsOn: [':digdag-cli:classpath']){
doLast {
}
}
task swaggerYaml(dependsOn: ':digdag-cli:shadowJar') {
doLast {
file("config/dummy.properties").write("")
Process server = ["java", "-jar", "digdag-cli/build/libs/digdag-cli-${project.version}-all.jar", "server", "-c", "config/dummy.properties", "--memory", "--enable-swagger"].execute()
sleep(5 * 1000)
["curl", "http://127.0.0.1:65432/api/swagger.yaml", "-o", "digdag-docs/src/_extra/api/swagger.yaml"].execute().waitFor()
server.destroy()
server.waitForOrKill(1000)
}
}
clean {
delete 'classpath'
delete 'pkg'
delete 'digdag-ui/public'
}
task release() {
release.mustRunAfter cli
dependsOn subprojects.findAll{it.name != "digdag-docs" }.publishMavenJavaPublicationToMavenCentralRepository
//ToDo upload executable to GitHub
doLast {
println "Released ${project.version}."
}
}
check.dependsOn('releaseCheck')
task setVersion {
doLast {
if (!project.hasProperty("to")) {
throw new GradleException("Usage: ./gradlew setVersion -Pto=VERSION")
}
File gradle_ver = file('build.gradle')
gradle_ver.write(gradle_ver.getText().replaceFirst("version = '(\\d+)(\\.\\d+){2}(-[\\d\\w]+)?'", "version = '${to}'"))
List<String> files = [
'digdag-client/src/main/resources/io/digdag/client/version.txt',
'digdag-cli/src/main/java/io/digdag/cli/Main.java',
'digdag-cli/src/main/java/io/digdag/cli/SelfUpdate.java',
]
files.each() { path ->
File doc = file(path)
doc.write(doc.getText().replaceAll("0\\.[1-9][0-9]*\\.(\\d+)(-[\\d\\w]+)?", "${to}"))
}
if (!to.endsWith('-SNAPSHOT')) {
// update docs
[
'digdag-docs/src/command_reference.rst',
].each() { path ->
File doc = file(path)
doc.write(doc.getText().replaceAll("0\\.[1-9][0-9]*\\.(\\d+)(-[\\d\\w]+)?", "${to}"))
}
// releases.rst
File releases = file("digdag-docs/src/releases.rst")
releases.write(releases.getText().replaceAll("# add new version here", "# add new version here\n releases/release-${to}"))
// release-<versionr>.rst
String notePath = "digdag-docs/src/releases/release-${to}.rst"
file(notePath).append(
"Release ${to}\n" +
"==============\n" +
"\n" +
"...\n" +
"\n" +
"Release Date\n" +
"------------\n" +
"${new Date().format('yyyy-MM-dd')}\n" +
"\n" +
"Contributors\n" +
"------------\n")
["bash", "-c", "git shortlog -s \$(git tag --sort=-creatordate | head -n 1)..HEAD | awk '{\$1=\"\";print \"*\" \$0}' >> ${notePath}"].execute().waitFor()
"git add ${notePath}".execute().waitFor()
}
}
}
task releaseCheck {
doLast {
if (project.ext.isSnapshotRelease) {
println "Releasing a SNAPSHOT version."
}
else {
if (!file("digdag-client/src/main/resources/io/digdag/client/version.txt").getText().contains("${project.version}")) {
throw new GradleException("digdag-client/src/main/resources/io/digdag/client/version.txt doesn't include ${project.version}")
}
if (!file("digdag-docs/src/releases/release-${project.version}.rst").getText().contains("${project.version}")) {
throw new GradleException("Release note for ${project.version} doesn't exist")
}
if (!file("digdag-docs/src/releases.rst").getText().contains("release-${project.version}")) {
throw new GradleException("digdag-docs/src/releases.rst doesn't include release-${project.version}")
}
String date = new Date().format("yyyy-MM-dd")
if (!file("digdag-docs/src/releases/release-${project.version}.rst").getText().contains(date)) {
throw new GradleException("digdag-docs/src/releases/release-${project.version}.rst doesn't include today's release date")
}
// TODO check git-ls-files includes release-<version>.rst file
println "Ready. Run 'release' task."
}
}
}
// Utility task to release a snapshot version with a fixed version number.
task releaseSnapshot(type: Exec) {
commandLine "bash", "-c", "./gradlew -PsnapshotVersion=\$(TZ=UTC git log -n 1 --pretty='format:%ad-%H' --date 'format-local:%Y%m%dT%H%M%S') release"
}
// Generate parent maven manifest
task pom {
doLast {
pom {
project {
packaging 'pom'
properties {
project {
build {
sourceEncoding 'UTF-8'
}
}
}
modules {
subprojects.each {
module it.name
}
}
}
}.withXml {
// XXX (dano): http://stackoverflow.com/a/27978130
def build = asNode().appendNode('build', '')
def plugins = build.appendNode('plugins', '')
def compiler = plugins.appendNode('plugin', '')
compiler.appendNode('groupId', 'org.apache.maven.plugins')
compiler.appendNode('artifactId', 'maven-compiler-plugin')
compiler.appendNode('version', '3.5.1')
def compiler_configuration = compiler.appendNode('configuration', '')
compiler_configuration.appendNode('source', sourceCompatibility)
compiler_configuration.appendNode('target', targetCompatibility)
def enforcer = plugins.appendNode('plugin', '')
enforcer.appendNode('groupId', 'org.apache.maven.plugins')
enforcer.appendNode('artifactId', 'maven-enforcer-plugin')
enforcer.appendNode('version', '1.4.1')
def enforcer_executions = enforcer.appendNode('executions', '')
def enforcer_execution = enforcer_executions.appendNode('execution', '')
enforcer_execution.appendNode('id', 'enforce')
def enforcer_goals = enforcer_execution.appendNode('goals', '')
enforcer_goals.appendNode('goal', 'enforce')
def enforcer_execution_configuration = enforcer_execution.appendNode('configuration', '')
def enforcer_rules = enforcer_execution_configuration.appendNode('rules', '')
enforcer_rules.appendNode('requireUpperBoundDeps', '')
def jar = plugins.appendNode('plugin', '')
jar.appendNode('groupId', 'org.apache.maven.plugins')
jar.appendNode('artifactId', 'maven-jar-plugin')
jar.appendNode('version', '3.0.2')
def jar_executions = jar.appendNode('executions', '')
def jar_execution = jar_executions.appendNode('execution', '')
def jar_execution_goals = jar_execution.appendNode('goals', '')
jar_execution_goals.appendNode('goal', 'test-jar')
}.writeTo("pom.xml")
}
}
task runServer(type: JavaExec) {
classpath = project(":digdag-cli").sourceSets.main.runtimeClasspath
main = 'io.digdag.cli.Main'
args 'server',
'-c', '/dev/null',
'-m',
'-H', 'Access-Control-Allow-Origin=http://localhost:8080',
'-H', 'Access-Control-Allow-Headers=origin, content-type, accept, authorization',
'-H', 'Access-Control-Allow-Credentials=true',
'-H', 'Access-Control-Allow-Methods=GET, POST, PUT, DELETE, OPTIONS, HEAD',
'-H', 'Access-Control-Max-Age=1209600'
}