-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathbuild.gradle
executable file
·831 lines (689 loc) · 32.7 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
826
827
828
829
830
831
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerTagImage
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import java.time.Instant
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
gradlePluginPortal()
}
dependencies {
classpath group: 'kr.motd.gradle', name: 'sphinx-gradle-plugin', version: '2.10.1'
classpath "jp.classmethod.aws.reboot:gradle-aws-plugin-reboot:0.45"
classpath "com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
}
}
plugins {
id "net.ltgt.apt" version "0.21"
id "de.undercouch.download" version "3.2.0"
id "org.scoverage" version "8.0.3"
id 'maven-publish'
id "me.champeau.gradle.jmh" version "0.5.3"
id 'com.bmuschko.docker-java-application' version '9.4.0'
id "cz.alenkacz.gradle.scalafmt" version "1.16.2"
id "java-library"
}
apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'kr.motd.sphinx'
apply plugin: 'application'
apply plugin: 'ManifestClasspath'
apply plugin: 'scalafmt'
group = 'beam'
version = '1.0.beta'
description = """"""
sourceCompatibility = 1.11
targetCompatibility = 1.11
scala {
zincVersion = "1.9.2"
}
//java {
// toolchain {
// languageVersion.set(JavaLanguageVersion.of(11))
// }
//}
compileScala.options.encoding = 'UTF-8'
compileScala.scalaCompileOptions.additionalParameters = ["-Xmx1g", "-W"]
// TODO temporary, drop this after matsim 0.10 -> 12.0 migration is fully complete
//compileScala.scalaCompileOptions.deprecation = false
def scalaBinaryVersion = "2.12"
def scalaBinaryFullVersion = "${scalaBinaryVersion}.17"
def akkaBinaryVersion = "2.6.6"
def circeBinaryVersion = "0.13.0"
def slf4jVersion = "1.7.25"
def kamonVersion = "2.0.3"
def tscfgVersion = "0.9.4"
sourceSets.main.scala.srcDirs = ["src/main/scala", "src/main/java"]
sourceSets.main.java.srcDirs = []
sourceSets.test.java.srcDirs = []
sourceSets.test.scala.srcDirs = ["src/test/scala", "src/test/java"]
sourceSets {
main {
resources {
srcDir "src/main/resources"
}
}
test {
resources {
srcDir "src/test/resources"
}
}
}
if (project.hasProperty('env')) {
sourceSets {
main {
resources {
srcDirs "test/input/" + project.getProperty('env')
}
}
}
}
allprojects {
repositories {
mavenCentral().content {
excludeModule("javax.media", "jai_core")
}
maven { url "https://repo.osgeo.org/repository/release/" }
maven { url "https://download.osgeo.org/webdav/geotools" }
// maven { url "http://maven.icm.edu.pl/artifactory/repo/" }
// maven { url "https://maven.geotoolkit.org/" }
maven { url "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases" }
maven { url "https://repo.maven.apache.org/maven2" }
maven { url "https://repo.matsim.org/repository/matsim" }
// Used for graphql-java and matsim.contrib.decongestion specific versions -
maven {
url "http://beam-bintray-needed-releases.s3-website.us-east-2.amazonaws.com/"
allowInsecureProtocol = true
}
maven { url "https://maven.conveyal.com/" }
maven { url "https://repo1.maven.org/maven2" }
maven { url "https://download.java.net/maven/2/" }
maven { url "https://people.apache.org/repo/m1-ibiblio-rsync-repository/org.apache.axis2/" }
maven { url "https://maven.geo-solutions.it" }
maven { url "https://mvn.topobyte.de" }
maven { url "https://mvn.slimjars.com" }
mavenLocal()
maven { url "https://jitpack.io" }
}
}
configurations {
scalaCompilerPlugin
}
configurations.all {
resolutionStrategy {
// we need this in order to get Elki library working fine.
force 'net.jafama:jafama:2.3.2'
// we need this in order to get Elki library working fine.
force 'it.unimi.dsi:fastutil:8.5.4'
force 'org.apache.logging.log4j:log4j-core:2.15.0'
force 'org.apache.logging.log4j:log4j-api:2.15.0'
}
exclude group: "log4j", module: "log4j"
exclude group: "org.matsim", module: "matsim"
}
dependencies {
// TODO FIXME
implementation(group: 'com.github.LBNL-UCB-STI', name: 'beam-utilities', version: '0.3.4')
////////////////////////////
// Java dependencies
////////////////////////////
implementation group: 'com.google.inject', name: 'guice', version: '4.1.0'
implementation group: 'com.google.inject.extensions', name: 'guice-assistedinject', version: '4.1.0'
implementation group: 'com.google.inject.extensions', name: 'guice-multibindings', version: '4.1.0'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
implementation group: 'org.apache.httpcomponents', name: 'fluent-hc', version: '4.5.13'
// Apache 2.0
implementation group: 'com.univocity', name: 'univocity-parsers', version: '2.9.1'
// LGPL
implementation group: 'org.geotools', name: 'gt-main', version: '21.5'
implementation group: 'org.geotools', name: 'gt-shapefile', version: '21.5'
implementation group: 'org.geotools', name: 'gt-referencing', version: '21.5'
implementation group: 'org.geotools', name: 'gt-epsg-wkt', version: '21.5'
implementation group: 'org.jfree', name: 'jfreechart', version: '1.0.14'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.3'
implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-scala_2.12', version: '2.12.3'
implementation group: 'javax.inject', name: 'javax.inject', version: '1'
implementation group: 'jdom', name: 'jdom', version: '1.1'
implementation group: 'org.jdom', name: 'jdom2', version: '2.0.5'
implementation 'com.hubspot.jinjava:jinjava:2.0.5'
implementation group: 'org.yaml', name: 'snakeyaml', version: '1.18'
implementation group: 'commons-io', name: 'commons-io', version: '2.5'
implementation 'net.sf.supercsv:super-csv:2.4.0'
implementation 'org.reflections:reflections:0.9.10'
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.2-b01'
implementation group: 'com.github.stephenc.eaio-uuid', name: "uuid", version: "3.4.0"
implementation "org.jgrapht:jgrapht-core:1.3.0"
implementation('com.github.LBNL-UCB-STI:or-tools-wrapper:7.5-0') {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}
implementation 'com.github.LBNL-UCB-STI:helics-wrapper:v3.3.0'
// GPLv3
implementation group: 'org.matsim.contrib', name: 'multimodal', version: '12.0'
implementation group: 'org.matsim.contrib', name: 'bicycle', version: '12.0'
implementation(group: 'org.matsim.contrib', name: 'decongestion', version: '12.0')
implementation(group: 'com.github.LBNL-UCB-STI.matsim', name: 'matsim', version: '12.0-beam-8') {
exclude group: 'log4j', module: 'log4j'
}
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
implementation "ch.qos.logback:logback-classic:1.2.3"
implementation "com.typesafe.scala-logging:scala-logging_${scalaBinaryVersion}:3.9.0"
implementation "org.slf4j:log4j-over-slf4j:${slf4jVersion}"
implementation(group: 'com.github.LBNL-UCB-STI', name: 'r5', version: 'v4.9.0') {
exclude group: 'ch.qos.logback', module: 'logback-classic'
exclude group: 'org.slf4j', module: 'slf4j-simple'
}
implementation group: 'com.graphhopper', name: 'graphhopper-core', version: '2.3'
implementation "com.sigopt:sigopt-java:4.9.0"
implementation group: 'com.graphhopper', name: 'graphhopper-reader-osm', version: '1.0'
implementation("com.uber:h3:3.7.2")
implementation("com.github.LBNL-UCB-STI:jsprit-wrapper:v0.5.1")
implementation("com.github.LBNL-UCB-STI:omx-java:v2.0.2")
testImplementation group: 'junit', name: 'junit', version: '4.8'
testImplementation group: 'org.mockito', name: 'mockito-inline', version: '2.27.0'
testImplementation group: "org.mockito", name: "mockito-core", version: "2.28.2"
jmhImplementation group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.23'
jmhImplementation group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.23'
/////////////////////////////////
// Scala dependencies
/////////////////////////////////
// CORE Scala //
implementation "org.scala-lang:scala-library:2.12.16"
implementation group: 'org.scala-lang.modules', name: "scala-xml_${scalaBinaryVersion}", version: '1.0.6'
// NEEDED FOR USING REPL //
implementation "org.scala-lang:scala-compiler:2.12.16"
// TEST Scala //
testImplementation group: 'org.scalatest', name: "scalatest_${scalaBinaryVersion}", version: '3.2.9'
testImplementation group: 'org.scalatestplus', name: 'scalatestplus-junit_2.12', version: '1.0.0-M2'
testRuntimeOnly "org.pegdown:pegdown:1.6.0"
// HTML report for scalatest
testImplementation group: 'com.vladsch.flexmark', name: 'flexmark-all', version: '0.36.8'
// 3rd Party Scala //
implementation group: 'org.jliszka', name: 'probability-monad_2.11', version: '1.0.1'
// https://mvnrepository.com/artifact/com.beachape/enumeratum_2.12
implementation group: 'com.beachape', name: "enumeratum_${scalaBinaryVersion}", version: "1.5.12"
// https://mvnrepository.com/artifact/com.beachape/enumeratum-circe_2.12
implementation group: 'com.beachape', name: "enumeratum-circe_${scalaBinaryVersion}", version: "1.5.14"
implementation "com.github.scopt:scopt_${scalaBinaryVersion}:4.0.0-RC2"
implementation "net.codingwell:scala-guice_${scalaBinaryVersion}:4.1.0" // DI
implementation('com.github.carueda:tscfg:v' + tscfgVersion) { // config
exclude group: 'org.scala-lang.modules', module: 'scala-xml_2.11'
exclude group: 'com.typesafe', module: 'config'
}
implementation group: 'com.typesafe', name: 'config', version: '1.4.0'
// https://mvnrepository.com/artifact/io.circe/circe-core_2.12
implementation group: 'io.circe', name: "circe-core_${scalaBinaryVersion}", version: circeBinaryVersion
// https://mvnrepository.com/artifact/io.circe/circe-generic_2.12
implementation group: 'io.circe', name: "circe-generic_${scalaBinaryVersion}", version: circeBinaryVersion
// https://mvnrepository.com/artifact/io.circe/circe-parser_2.12
implementation group: 'io.circe', name: "circe-parser_${scalaBinaryVersion}", version: circeBinaryVersion
implementation group: 'com.typesafe.play', name: "play-json_${scalaBinaryVersion}", version: '2.6.3'
implementation(group: 'com.github.romix.akka', name: "akka-kryo-serialization_${scalaBinaryVersion}", version: '0.5.2') {
exclude group: 'com.esotericsoftware', module: 'kryo'
}
implementation group: 'com.esotericsoftware', name: 'kryo', version: '4.0.2'
implementation "com.github.vagmcs:optimus_${scalaBinaryVersion}:3.1.0"
implementation "com.github.vagmcs:optimus-solver-oj_${scalaBinaryVersion}:3.1.0"
implementation group: 'io.spray', name: 'spray-json_2.12', version: '1.3.5'
////////////////////////////////////
///Performance Monitoring (Kamon)///
////////////////////////////////////
// compile("io.kamon:kamon-bundle_${scalaBinaryVersion}:${kamonVersion}")
implementation("io.kamon:kamon-core_${scalaBinaryVersion}:2.0.1")
// compile("io.kamon:kamon-influxdb_2.12:2.0.0")
implementation("org.influxdb:influxdb-java:2.16")
/////////////
// Akka Dependencies
////////////
// CORE Akka //
implementation group: 'com.typesafe.akka', name: "akka-actor_${scalaBinaryVersion}", version: akkaBinaryVersion
implementation group: 'com.typesafe.akka', name: "akka-slf4j_${scalaBinaryVersion}", version: akkaBinaryVersion
implementation group: 'com.typesafe.akka', name: "akka-cluster_${scalaBinaryVersion}", version: akkaBinaryVersion
implementation group: 'com.typesafe.akka', name: "akka-cluster-tools_${scalaBinaryVersion}", version: akkaBinaryVersion
implementation group: 'com.typesafe.akka', name: "akka-http_${scalaBinaryVersion}", version: "10.1.12"
implementation group: 'de.heikoseeberger', name: "akka-http-circe_${scalaBinaryVersion}", version: "1.25.2"
// TEST Akka //
testImplementation group: 'com.typesafe.akka', name: "akka-testkit_${scalaBinaryVersion}", version: akkaBinaryVersion
scoverage "org.scoverage:scalac-scoverage-plugin_${scalaBinaryFullVersion}:2.0.10", "org.scoverage:scalac-scoverage-runtime_${scalaBinaryVersion}:2.0.10"
implementation 'org.apache.commons:commons-compress:1.18'
implementation group: 'de.lmu.ifi.dbs.elki', name: 'elki', version: '0.7.5'
implementation group: 'com.zaxxer', name: 'nuprocess', version: '1.2.4'
def parquet = "1.12.3"
implementation group: 'org.apache.parquet', name: 'parquet-hadoop', version: parquet
implementation group: 'org.apache.parquet', name: 'parquet-avro', version: parquet
implementation(group: 'org.apache.hadoop', name: 'hadoop-client', version: '2.7.3') {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
// Exclude `ASM` because it is binary incompatible with the one which is gotten from `com.conveyal:kryo-tools`: `org.ow2.asm:asm:5.0.4`
exclude group: 'asm', module: 'asm'
// Exclude jsp-api because it contains an older version of javax.el (Expression Language) which is incompatible
// with one that Hibernate-validator uses
exclude group: 'javax.servlet.jsp', module: 'jsp-api'
}
implementation(group: 'com.lihaoyi', name: "sourcecode_${scalaBinaryVersion}", version: '0.1.9')
implementation "com.github.vagmcs:optimus_${scalaBinaryVersion}:3.1.0"
implementation group: 'com.google.maps', name: 'google-maps-services', version: '0.14.0'
implementation group: 'org.onebusaway', name: 'onebusaway-gtfs-transformer', version: '1.3.4'
implementation 'de.vandermeer:asciitable:0.3.2'
implementation "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}.13:1.4.8"
scalaCompilerPlugin "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}.13:1.4.8"
// AWS S3
implementation group: 'software.amazon.awssdk', name: 's3', version: '2.16.68'
implementation group: 'org.ini4j', name: 'ini4j', version: '0.5.4'
}
// Autoformatting using scalafmt
scalafmt {
// configFilePath = ".scalafmt.conf" // .scalafmt.conf in the project root is default value, provide only if other location is needed
}
//compileScala.dependsOn(scalafmtAll)
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
task install(dependsOn: 'publishToMavenLocal')
tasks.withType(cz.alenkacz.gradle.scalafmt.ScalafmtFormatBase) {
outputs.upToDateWhen { false }
}
tasks.withType(ScalaCompile) {
// LooksLikeInterpolatedString must stay
def additionalParameters = ["-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
"-P:scapegoat:dataDir:" + buildDir + "/reports/scapegoat",
"-P:scapegoat:reports:html:xml",
"-P:scapegoat:disabledInspections:OptionGet:UnsafeTraversableMethods:TryGet:EitherGet:AsInstanceOf:NullAssignment:VariableShadowing:NullParameter:MethodReturningAny:IsInstanceOf:EmptyIfBlock:CatchException:EmptyInterpolatedString:UnnecessaryConversion:CatchThrowable:CollectionIndexOnNonIndexedSeq:AvoidSizeNotEqualsZero:ComparingFloatingPointTypes:UnsafeContains:VarCouldBeVal:CatchThrowable:SuspiciousMatchOnClassObject:VarClosure:RepeatedIfElseBody:LooksLikeInterpolatedString",
"-P:scapegoat:verbose:false",
"-P:scapegoat:consoleOutput:true"]
def minimumCompilationParameters = ["-unchecked", "-feature"]
if (project.hasProperty("report")) {
scalaCompileOptions.additionalParameters = minimumCompilationParameters + additionalParameters
} else {
scalaCompileOptions.additionalParameters = minimumCompilationParameters + additionalParameters + ["-Xfatal-warnings"]
}
scalaCompileOptions.forkOptions.with {
memoryMaximumSize = '2g'
}
}
tasks.withType(JavaExec).configureEach { task ->
if (!task.name.equals("run")) {
jvmArgs = project.hasProperty('logbackCfg') ? ["-Dlogback.configurationFile=${project.property('logbackCfg')}"] : []
}
}
// Task to run scala tests, as Scala tests not picked up by Gradle by default.
// You can run it with a number of threads: ./gradlew spec -PnumThreads=4
task spec(dependsOn: ['testClasses'], type: JavaExec) {
def n = project.hasProperty('numThreads') ? numThreads : 4
mainClass = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-h', 'build/scalatest-report', '-u', 'build/scalatest-report-xml', '-oD', '-l', 'beam.tags.ExcludeRegular',
"-PS$n", '-T', '120', '-W', '300', '60']
classpath = sourceSets.test.runtimeClasspath
}
build.dependsOn spec
/* //////////////////////////////////////////////////
* Task to run tagged tests.
* Note: use space separated list of tags
* ./gradlew taggedTest -Ptags="beam.tags.Performance beam.tags.Integration"
* /////////////////////////////////////////////////// */
processResources {
duplicatesStrategy = 'include'
}
processTestResources {
duplicatesStrategy = 'include'
}
task taggedTest(dependsOn: ['testClasses'], type: JavaExec) {
mainClass = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-o', '-n'] << (project.findProperty('tags') ?: 'org.scalatest.Ignore')
classpath = sourceSets.test.runtimeClasspath
}
task specificTest(dependsOn: ['testClasses'], type: JavaExec) {
mainClass = 'org.scalatest.tools.Runner'
args = (['-R', 'build/classes/scala/test', '-o', '-s'] << (project.findProperty('suite') ?: 'org.scalatest.Ignore')) +
(project.hasProperty('matches') ? ["-z", project.findProperty('matches')] : [])
classpath = sourceSets.test.runtimeClasspath
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Task to run tests periodically on continue integration server.
// ./gradlew periodicTest -Pconfig=test/input/sf-light/sf-light-1k.conf -Piterations=1
////////////////////////////////////////////////////////////////////////////////////////////////////////////
task periodicTest(dependsOn: ['testClasses'], type: JavaExec) {
mainClass = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-o', '-n', 'beam.tags.Periodic'] <<
(project.hasProperty('config') ? '-Dconfig=' + project.findProperty('config') :
(project.hasProperty('iterations') ? '-Diterations=' + project.findProperty('iterations') : '')) <<
(project.hasProperty('config') && project.hasProperty('iterations') ?
'-Diterations=' + project.findProperty('iterations') : '')
jvmArgs = ['-javaagent:build/aspectjweaver-1.8.10.jar']
classpath = sourceSets.test.runtimeClasspath
doFirst() {
if (!project.file('build/aspectjweaver-1.8.10.jar').exists()) {
download {
src 'https://repo1.maven.org/maven2/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar'
dest buildDir
}
}
}
}
//////////////////////////////////////////////////////////////////////
// Generate config classes reflecting the application.conf file
//////////////////////////////////////////////////////////////////////
task generateConfig {
doLast {
def tscfgJarFile = project.file('build/tscfg-' + tscfgVersion + '.jar')
if (!tscfgJarFile.exists() || !tscfgJarFile.isFile()) {
download {
src 'https://github.com/carueda/tscfg/releases/download/v' + tscfgVersion + '/tscfg-' + tscfgVersion + '.jar'
dest buildDir
}
}
javaexec {
main = "-jar"
args = [
"build/tscfg-${tscfgVersion}.jar",
"--spec", "src/main/resources/beam-template.conf",
"--scala",
"--pn", "beam.sim.config",
"--cn", "BeamConfig",
"--dd", "src/main/scala/beam/sim/" //This is temp location. Actual location will be updated by copyConfigWithoutTimeStamp
]
}
}
}
task copyConfigWithoutTimeStamp(type: Copy) {
from 'src/main/scala/beam/sim/BeamConfig.scala'
into 'src/main/scala/beam/sim/config/'
filter { line -> line.contains('generated by tscfg') ? null : line }
}
//Deletion of temp generated config
task removeTempConfig(type: Delete) {
delete 'src/main/scala/beam/sim/BeamConfig.scala'
}
generateConfig.finalizedBy(copyConfigWithoutTimeStamp)
copyConfigWithoutTimeStamp.finalizedBy(removeTempConfig)
task repl(type: JavaExec) {
mainClass = "scala.tools.nsc.MainGenericRunner"
classpath = sourceSets.main.runtimeClasspath
standardInput System.in
args '-usejavacp'
}
task deleteSf {
doLast {
if (project.file('production/application-sfbay/r5/network.dat').exists()) {
delete 'production/application-sfbay/r5/network.dat'
}
if (project.file('production/application-sfbay/r5/osm.mapdb').exists()) {
delete 'production/application-sfbay/r5/osm.mapdb'
}
if (project.file('production/application-sfbay/r5/osm.mapdb.p').exists()) {
delete 'production/application-sfbay/r5/osm.mapdb.p'
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Run Via application plugin
// Note: colon preceding "run" is necessary to only run the main project and not launch the GUI as well.
// ./gradlew :run -PappArgs="['--config', 'production/application-sfbay/beam.conf']"
////////////////////////////////////////////////////////////////////////////////////////////////////////////
mainClassName = "beam.sim.RunBeam"
def myAvailableRam = (System.getenv("MAXRAM") ?: (project.findProperty('maxRAM') ?: "140"))
.toString()
.replace("g", "")
.toFloat() // because otherwise 'toInteger' might throw java.lang.NumberFormatException
.toInteger()
def halfOfAvailableMem = (myAvailableRam / 2).toInteger()
def getCurrentTimestamp = {
DateTimeFormatter.ofPattern("MM-dd-yyyy_HH-mm-ss")
.withLocale(Locale.US)
.withZone(ZoneOffset.UTC)
.format(Instant.now())
}
def logGC = ["-XX:+PrintGCDetails", "-Xloggc:gc_${getCurrentTimestamp()}.log"]
// Use following for remote debug mode
def remoteDebug = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8005"]
def jfr = ["-XX:+UnlockCommercialFeatures", "-XX:+FlightRecorder",
"-XX:FlightRecorderOptions=defaultrecording=true,disk=true,maxage=10h,dumponexit=true,loglevel=info"]
// On the running machine there should be file /usr/lib/jvm/java-8-oracle/jre/lib/jfr/profile_heap_exception.jfc with content from
// https://pastebin.com/N3uuUfPz - it's Java Mission Control with metrics about heap allocation and details about exceptions
def jfrWithMem = ["-XX:+UnlockCommercialFeatures", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints",
"-XX:StartFlightRecording=delay=2s,duration=180m,name=mem_ex,filename=recording.jfr,settings=profile_heap_exception",
"-XX:+FlightRecorder", "-XX:FlightRecorderOptions=disk=true,maxage=10h,dumponexit=true,loglevel=info"]
def jmx = ["-Dcom.sun.management.jmxremote", "-Dcom.sun.management.jmxremote.port=9005", "-Dcom.sun.management.jmxremote.rmi.port=9005", "-Dcom.sun.management.jmxremote.host=127.0.0.1",
"-Dcom.sun.management.jmxremote.local.only=true", "-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.ssl=false",
"-Djava.net.preferIPv4Stack=true", "-Djava.rmi.server.hostname=127.0.0.1"]
def logbackConfig = project.findProperty('logbackCfg') ?: "logback_prod.xml"
def profilerTypeConfig = project.findProperty('profiler_type') ?: ""
def profilerOption = []
if (profilerTypeConfig.toString().equalsIgnoreCase('cpu')) {
profilerOption = jfr
} else if (profilerTypeConfig.toString().equalsIgnoreCase('cpumem')) {
profilerOption = jfrWithMem
}
// UseParallelGC
applicationDefaultJvmArgs = ["-Xmx${myAvailableRam}g", "-Xms${halfOfAvailableMem}g",
"-XX:+UseParallelGC", "-XX:+UseParallelOldGC", "-XX:MetaspaceSize=150M", "-Djava.awt.headless=true",
"-Dlogback.configurationFile=${logbackConfig}", "-Xss2048k"] + profilerOption + logGC + jmx
println(applicationDefaultJvmArgs)
run {
if (project.hasProperty("appArgs")) {
args Eval.me(appArgs)
}
doFirst() {
if (!project.file('build/aspectjweaver-1.8.10.jar').exists()) {
download {
src 'https://repo1.maven.org/maven2/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar'
dest buildDir
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Run ExperimentGenerator from Command line
// gradle :execute -PmainClass=scripts.experiment.ExperimentGenerator -PappArgs="['--experiments', 'test/input/beamville/example-experiment/experiment.yml']"
// Run R5 GUI server
// gradle --stacktrace :execute -PmainClass=com.conveyal.r5.R5Main -PappArgs="['point','--graphs','production/application-sfbay/r5/']"
////////////////////////////////////////////////////////////////////////////////////////////////////////////
task execute(type: JavaExec) {
jvmArgs = applicationDefaultJvmArgs
if (project.hasProperty("mainClass")) {
mainClass = project.property("mainClass")
} else {
mainClass = mainClassName
}
classpath = sourceSets.main.runtimeClasspath
if (project.hasProperty("appArgs")) {
args Eval.me(appArgs)
}
doFirst() {
if (!project.file('build/aspectjweaver-1.8.10.jar').exists()) {
download {
src 'https://repo1.maven.org/maven2/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar'
dest buildDir
}
}
}
}
task matsimConversion(type: JavaExec) {
mainClass = 'beam.utils.matsim_conversion.MatsimConversionTool'
classpath = sourceSets.main.runtimeClasspath
environment "PWD", "na"
if (project.hasProperty("confPath")) {
args Eval.me(confPath)
// if this triggers an error, try
// args "${confPath}"
}
}
task generateDocumentation(type: JavaExec) {
group 'Documentation'
description 'Format the data using Sphinx RST formats'
mainClass = 'scripts.docs.GenerateDocumentationTask'
classpath = sourceSets.main.runtimeClasspath
}
task fmt(dependsOn: scalafmtAll)
task verifyScalaFmtHasBeenRun() {
doLast {
try {
def workingDir = new File("${project.projectDir}")
def result = 'git diff --exit-code --quiet'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() != 0) throw new Exception("""
Please run ./gradlew scalaFmtAll and commit/push the subsequent results to fix this error.
This happened because a git diff yielded a non-zero exit code.
This task was built to be run on the CI server AFTER scalaFmtAll
It should only error if the results of scalaFmtAll resulted in code modifications.
And that would only happen if the committed code is not formatted as expected.""")
} catch (e) {
throw new Exception("An unexpected error was encountered while checking that scalaFmtAll was committed.", e)
}
}
}
docker {
registryCredentials {
url = 'https://index.docker.io/v1/'
username = System.getenv("DOCKER_USER")
password = System.getenv("DOCKER_PASSWORD")
}
}
dockerSyncBuildContext {
from('src/main/python') {
into('src/main/python')
}
from('test/input/common') {
into('test/input/common')
}
from('test/input/dtd') {
into('test/input/dtd')
}
from('test/input/beamville') {
into('test/input/beamville')
}
from('test/input/sf-light') {
into('test/input/sf-light')
}
from file('docker/entrypoint.sh')
}
jmh {
// https://github.com/melix/jmh-gradle-plugin/issues/107
jvmArgs = ['-Djmh.separateClasspathJAR=true', '-Dbeam.home=' + project.projectDir]
duplicateClassesStrategy = 'exclude'
zip64 = true
}
tasks.register('deploy') {
def cloudPlatform = null
def paramName = "cloudPlatform"
if (project.hasProperty(paramName)) {
cloudPlatform = project.findProperty(paramName)
} else {
def propsFileName = "./gradle.deploy.properties"
if (project.hasProperty('propsFile')) {
propsFileName = project.findProperty('propsFile')
}
def propsFile = new Properties()
propsFile.load(project.file(propsFileName).newDataInputStream())
cloudPlatform = propsFile.getProperty(paramName)
}
if (cloudPlatform == null) {
cloudPlatform = ""
}
switch (cloudPlatform.trim().toLowerCase()) {
case "amazon":
dependsOn ':aws:deployToEC2'
break
case "google":
dependsOn ':gcp:deployToGCE'
break
default:
throw new InvalidUserDataException("Cannot deploy! Please specify cloudPlatform property to one of [Google, Amazon]")
break
}
}
docker {
registryCredentials {
url = 'https://index.docker.io/v1/'
username = System.getenv("DOCKER_USER")
password = System.getenv("DOCKER_PASSWORD")
}
}
dockerSyncBuildContext {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from('src/main/python') {
into('src/main/python')
}
from('test/input/common') {
into('test/input/common')
}
from('test/input/dtd') {
into('test/input/dtd')
}
from('test/input/beamville') {
into('test/input/beamville')
}
from('test/input/sf-light') {
into('test/input/sf-light')
}
from file('docker/entrypoint.sh')
}
// Some examples of manual docker file creation can be found https://github.com/bmuschko/gradle-docker-plugin/blob/3736ff644bed1cbfeed6fc7f844a5513c4208bc2/src/functTest/groovy/com/bmuschko/gradle/docker/DockerWorkflowFunctionalTest.groovy#L24
// Also here: https://bmuschko.github.io/gradle-docker-plugin/#modifying_instructions_of_a_dockerfile_task
tasks.register('createDockerfile', Dockerfile) {
dependsOn dockerSyncBuildContext
// assuming all required modules / dependencies are installed in beammodel/beam-environment
from 'beammodel/beam-environment:jdk-11-4.01'
label(['maintainer': 'LBNL Beam Team'])
workingDir("/app")
instruction 'RUN mkdir /app/output'
// dependencies, resources and compiled Java classes
copyFile("libs", "libs")
copyFile("resources", "resources")
copyFile("classes", "classes")
// Test scenarios
copyFile("test/input/common", "test/input/common")
copyFile("test/input/dtd", "test/input/dtd")
copyFile("test/input/beamville", "test/input/beamville")
copyFile("test/input/sf-light", "test/input/sf-light")
// python scripts
addFile 'src/main/python', 'src/main/python'
// entry point
addFile 'entrypoint.sh', 'entrypoint.sh'
runCommand('chmod +x /app/entrypoint.sh')
entryPoint('/app/entrypoint.sh')
}
ext.getDockerTag = { ->
if (project.hasProperty("tag")) {
def split_vals = (project.findProperty("tag") as String).split(':')
if (split_vals.size() > 1) {
return split_vals[1]
} else {
return ""
}
} else {
return ""
}
}
ext.getDockerRepository = { ->
if (project.hasProperty("tag")) {
def split_vals = (project.findProperty("tag") as String).split(':')
return split_vals[0]
} else {
return ""
}
}
tasks.register('buildImageWithoutTags', DockerBuildImage) { dependsOn createDockerfile }
// one can build a docker image with command ./gradlew -Ptag=beammodel/beam:0.9.12 buildImage
tasks.register('buildImage', DockerTagImage) {
description 'Builds the Docker BEAM image, all code and test data are included into the image.'
group 'Docker'
dependsOn buildImageWithoutTags
tag = getDockerTag()
repository = getDockerRepository()
println("The new image will be tagged '$getDockerRepository:$getDockerTag'. To change use 'tag' project parameter, i.e. '-Ptag=<value>'")
targetImageId buildImageWithoutTags.getImageId()
}