forked from TouK/nussknacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
2067 lines (1920 loc) · 87 KB
/
build.sbt
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
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import com.typesafe.sbt.packager.SettingsHelper
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.dockerUsername
import pl.project13.scala.sbt.JmhPlugin
import pl.project13.scala.sbt.JmhPlugin._
import sbt.Keys._
import sbt._
import sbtassembly.AssemblyPlugin.autoImport.assembly
import sbtassembly.MergeStrategy
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
import scala.language.postfixOps
import scala.sys.process._
import scala.util.Try
import scala.xml.Elem
import scala.xml.transform.{RewriteRule, RuleTransformer}
// Warning: Flink doesn't work correctly with 2.12.11
// Warning: 2.12.13 + crossVersion break sbt-scoverage: https://github.com/scoverage/sbt-scoverage/issues/319
val scala212 = "2.12.10"
val scala213 = "2.13.12"
val defaultScalaV = sys.env.getOrElse("NUSSKNACKER_SCALA_VERSION", "2.13") match {
case "2.12" => scala212
case "2.13" => scala213
}
lazy val supportedScalaVersions = List(scala212, scala213)
// Silencer must be compatible with exact scala version - see compatibility matrix: https://search.maven.org/search?q=silencer-plugin
// Silencer 1.7.x require Scala 2.12.11 (see warning above)
// Silencer (and all '@silent' annotations) can be removed after we can upgrade to 2.12.13...
// https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html
lazy val silencerV = "1.7.14"
lazy val silencerV_2_12 = "1.6.0"
//TODO: replace configuration by system properties with configuration via environment after removing travis scripts
//then we can change names to snake case, for "normal" env variables
def propOrEnv(name: String, default: String): String = propOrEnv(name).getOrElse(default)
def propOrEnv(name: String): Option[String] = Option(System.getProperty(name)).orElse(sys.env.get(name))
//by default we include flink and scala, we want to be able to disable this behaviour for performance reasons
val includeFlinkAndScala = propOrEnv("includeFlinkAndScala", "true").toBoolean
val flinkScope = if (includeFlinkAndScala) "compile" else "provided"
val nexusUrlFromProps = propOrEnv("nexusUrl")
//TODO: this is pretty clunky, but works so far for our case...
val nexusHostFromProps = nexusUrlFromProps.map(_.replaceAll("http[s]?://", "").replaceAll("[:/].*", ""))
//Docker release configuration
val dockerTagName = propOrEnv("dockerTagName")
val dockerPort = propOrEnv("dockerPort", "8080").toInt
val dockerUserName = Option(propOrEnv("dockerUserName", "touk"))
val dockerPackageName = propOrEnv("dockerPackageName", "nussknacker")
val dockerUpLatestFromProp = propOrEnv("dockerUpLatest").flatMap(p => Try(p.toBoolean).toOption)
val dockerUpBranchLatestFromProp = propOrEnv("dockerUpBranchLatest", "true").toBoolean
val addDevArtifacts = propOrEnv("addDevArtifacts", "false").toBoolean
val addManagerArtifacts = propOrEnv("addManagerArtifacts", "false").toBoolean
val requestResponseManagementPort = propOrEnv("requestResponseManagementPort", "8070").toInt
val requestResponseProcessesPort = propOrEnv("requestResponseProcessesPort", "8080").toInt
val liteEngineKafkaRuntimeDockerPackageName =
propOrEnv("liteEngineKafkaRuntimeDockerPackageName", "nussknacker-lite-runtime-app")
// `publishArtifact := false` should be enough to keep sbt from publishing root module,
// unfortunately it does not work, so we resort to hack by publishing root module to Resolver.defaultLocal
//publishArtifact := false
publishTo := Some(Resolver.defaultLocal)
crossScalaVersions := Nil
ThisBuild / isSnapshot := version(_ contains "-SNAPSHOT").value
lazy val publishSettings = Seq(
publishMavenStyle := true,
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
publishTo := {
nexusUrlFromProps
.map { url =>
(if (isSnapshot.value) "snapshots" else "releases") at url
}
.orElse {
val defaultNexusUrl = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at defaultNexusUrl + "content/repositories/snapshots")
else
sonatypePublishToBundle.value
}
},
Test / publishArtifact := false,
// We don't put scm information here, it will be added by release plugin and if scm provided here is different than the one from scm
// we'll end up with two scm sections and invalid pom...
pomExtra in Global := {
<developers>
<developer>
<id>TouK</id>
<name>TouK</name>
<url>https://touk.pl</url>
</developer>
</developers>
},
organization := "pl.touk.nussknacker",
homepage := Some(url(s"https://github.com/touk/nussknacker")),
)
def modelMergeStrategy: String => MergeStrategy = {
case PathList(ps @ _*) if ps.last == "module-info.class" =>
MergeStrategy.discard // TODO: we don't handle JDK9 modules well
case PathList(ps @ _*) if ps.last == "NumberUtils.class" => MergeStrategy.first // TODO: shade Spring EL?
case PathList("org", "apache", "commons", "logging", _ @_*) => MergeStrategy.first // TODO: shade Spring EL?
case PathList(ps @ _*) if ps.last == "io.netty.versions.properties" =>
MergeStrategy.first // Netty has buildTime here, which is different for different modules :/
case PathList(ps @ _*) if ps.head == "draftv4" && ps.last == "schema" =>
MergeStrategy.first // Due to swagger-parser dependencies having different schema definitions
case x => MergeStrategy.defaultMergeStrategy(x)
}
def designerMergeStrategy: String => MergeStrategy = {
case PathList("META-INF", "maven", "org.webjars", "swagger-ui", "pom.properties") =>
MergeStrategy.singleOrError // https://tapir.softwaremill.com/en/latest/docs/openapi.html#using-swaggerui-with-sbt-assembly
case PathList(ps @ _*) if ps.last == "module-info.class" => MergeStrategy.discard
case PathList(ps @ _*) if ps.last == "NumberUtils.class" => MergeStrategy.first // TODO: shade Spring EL?
case PathList("org", "apache", "commons", "logging", _ @_*) => MergeStrategy.first // TODO: shade Spring EL?
case PathList(ps @ _*) if ps.last == "io.netty.versions.properties" =>
MergeStrategy.first // Netty has buildTime here, which is different for different modules :/
case PathList("com", "sun", "el", _ @_*) => MergeStrategy.first // Some legacy batik stuff
case PathList("org", "w3c", "dom", "events", _ @_*) => MergeStrategy.first // Some legacy batik stuff
case PathList(ps @ _*) if ps.head == "draftv4" && ps.last == "schema" =>
MergeStrategy.first // Due to swagger-parser dependencies having different schema definitions
case x => MergeStrategy.defaultMergeStrategy(x)
}
def requestResponseMergeStrategy: String => MergeStrategy = {
case PathList(ps @ _*) if ps.last == "module-info.class" => MergeStrategy.discard
case PathList(ps @ _*) if ps.last == "NumberUtils.class" => MergeStrategy.first // TODO: shade Spring EL?
case PathList("org", "apache", "commons", "logging", _ @_*) => MergeStrategy.first // TODO: shade Spring EL?
case PathList(ps @ _*) if ps.last == "io.netty.versions.properties" =>
MergeStrategy.first // Netty has buildTime here, which is different for different modules :/
case PathList(ps @ _*) if ps.head == "draftv4" && ps.last == "schema" =>
MergeStrategy.first // Due to swagger-parser dependencies having different schema definitions
case x => MergeStrategy.defaultMergeStrategy(x)
}
val scalaTestReports = Tests.Argument(TestFrameworks.ScalaTest, "-u", "target/surefire-reports", "-oFGD")
lazy val SlowTests = config("slow") extend Test
val slowTestsSettings =
inConfig(SlowTests)(Defaults.testTasks) ++ Seq(
SlowTests / testOptions := Seq(
Tests.Argument(TestFrameworks.ScalaTest, "-n", "org.scalatest.tags.Slow"),
scalaTestReports
)
)
val ignoreSlowTests = Tests.Argument(TestFrameworks.ScalaTest, "-l", "org.scalatest.tags.Slow")
// This scope is for purpose of running integration tests that need external deps to work (like working k8s client setup)
lazy val ExternalDepsTests = config("externaldeps") extend Test
val externalDepsTestsSettings =
inConfig(ExternalDepsTests)(Defaults.testTasks) ++ Seq(
ExternalDepsTests / testOptions := Seq(
// We use ready "Network" tag to avoid having some extra module only with this class
Tests.Argument(TestFrameworks.ScalaTest, "-n", "org.scalatest.tags.Network"),
scalaTestReports
)
)
val ignoreExternalDepsTests = Tests.Argument(TestFrameworks.ScalaTest, "-l", "org.scalatest.tags.Network")
def forScalaVersion[T](version: String, default: T, specific: ((Int, Int), T)*): T = {
CrossVersion
.partialVersion(version)
.flatMap { case (k, v) =>
specific.toMap.get((k.toInt, v.toInt))
}
.getOrElse(default)
}
lazy val commonSettings =
publishSettings ++
Seq(
assembly / test := {},
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html")),
crossScalaVersions := supportedScalaVersions,
scalaVersion := defaultScalaV,
resolvers ++= Seq(
"confluent" at "https://packages.confluent.io/maven",
),
// We ignore k8s tests to keep development setup low-dependency
Test / testOptions ++= Seq(scalaTestReports, ignoreSlowTests, ignoreExternalDepsTests),
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full),
libraryDependencies += compilerPlugin(
"com.github.ghik" % "silencer-plugin" % forScalaVersion(
scalaVersion.value,
silencerV,
(2, 12) -> silencerV_2_12
) cross CrossVersion.full
),
libraryDependencies ++= forScalaVersion(
scalaVersion.value,
Seq(),
(2, 12) -> Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full))
),
scalacOptions := Seq(
"-unchecked",
"-deprecation",
"-encoding",
"utf8",
"-Xfatal-warnings",
"-feature",
"-language:postfixOps",
"-language:existentials",
"-release",
"11"
) ++ forScalaVersion(
scalaVersion.value,
Seq(),
(2, 12) -> Seq(
"-Ypartial-unification",
// We use jdk standard lib classes from java 11, but Scala 2.12 does not support target > 8 and
// -release option has no influence on class version so we at least setup target to 8 and check java version
// at the begining of our Apps
"-target:jvm-1.8",
),
(2, 13) -> Seq(
"-Ymacro-annotations"
)
),
javacOptions := Seq(
"-Xlint:deprecation",
"-Xlint:unchecked",
// Using --release flag (available only on jdk >= 9) instead of -source -target to avoid usage of api from newer java version
"--release",
"11",
// we use it e.g. to provide consistent behaviour wrt extracting parameter names from scala and java
"-parameters"
),
coverageMinimumStmtTotal := 60,
coverageMinimumBranchTotal := 60,
coverageFailOnMinimum := false,
// problem with scaladoc of api: https://github.com/scala/bug/issues/10134
Compile / doc / scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= Seq(
"com.github.ghik" % "silencer-lib" % forScalaVersion(
scalaVersion.value,
silencerV,
(2, 12) -> silencerV_2_12
) % Provided cross CrossVersion.full
),
// here we add dependencies that we want to have fixed across all modules
dependencyOverrides ++= Seq(
// currently Flink (1.11 -> https://github.com/apache/flink/blob/master/pom.xml#L128) uses 1.8.2 Avro version
"org.apache.avro" % "avro" % avroV,
"com.typesafe" % "config" % configV,
"commons-io" % "commons-io" % flinkCommonsIOV,
"org.apache.commons" % "commons-text" % flinkCommonsTextV, // dependency of commons-lang3
"org.apache.commons" % "commons-lang3" % flinkCommonsLang3V,
"io.circe" %% "circe-core" % circeV,
"io.circe" %% "circe-parser" % circeV,
// Force akka-http and akka-stream versions to avoid bumping by akka-http-circe.
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV,
"com.typesafe.akka" %% "akka-stream" % akkaV,
"com.typesafe.akka" %% "akka-testkit" % akkaV,
"org.scala-lang.modules" %% "scala-java8-compat" % scalaCompatV,
// security features
"org.scala-lang.modules" %% "scala-xml" % "2.1.0",
// Our main kafka dependencies are Confluent (for avro) and Flink (Kafka connector)
"org.apache.kafka" % "kafka-clients" % kafkaV,
"org.apache.kafka" %% "kafka" % kafkaV,
"io.netty" % "netty-handler" % nettyV,
"io.netty" % "netty-codec" % nettyV,
"io.netty" % "netty-codec-http" % nettyV,
"io.netty" % "netty-codec-socks" % nettyV,
"io.netty" % "netty-handler-proxy" % nettyV,
"io.netty" % "netty-transport-native-epoll" % nettyV,
// For async-http-client
"com.typesafe.netty" % "netty-reactive-streams" % nettyReactiveStreamsV,
// Jackson is used by: openapi, jwks-rsa, kafka-json-schema-provider
"com.fasterxml.jackson.core" % "jackson-annotations" % jacksonV,
"com.fasterxml.jackson.core" % "jackson-core" % jacksonV,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonV,
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-cbor" % jacksonV,
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-toml" % jacksonV,
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % jacksonV,
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % jacksonV,
"com.fasterxml.jackson.datatype" % "jackson-datatype-jdk8" % jacksonV,
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % jacksonV,
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % jacksonV,
"com.fasterxml.jackson.module" % "jackson-module-parameter-names" % jacksonV,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonV,
"io.dropwizard.metrics5" % "metrics-core" % dropWizardV,
"io.dropwizard.metrics5" % "metrics-json" % dropWizardV,
"org.slf4j" % "slf4j-api" % slf4jV
)
)
// Note: when updating check versions in 'flink*V' below, because some libraries must be fixed at versions provided
// by Flink, or jobs may fail in runtime when Flink is run with 'classloader.resolve-order: parent-first'.
// You can find versions provided by Flink in it's lib/flink-dist-*.jar/META-INF/DEPENDENCIES file.
val flinkV = "1.16.3"
val flinkCommonsLang3V = "3.12.0"
val flinkCommonsTextV = "1.10.0"
val flinkCommonsIOV = "2.11.0"
val avroV = "1.11.1"
//we should use max(version used by confluent, version acceptable by flink), https://docs.confluent.io/platform/current/installation/versions-interoperability.html - confluent version reference
val kafkaV = "3.3.2"
//TODO: Spring 5.3 has some problem with handling our PrimitiveOrWrappersPropertyAccessor
val springV = "5.2.23.RELEASE"
val scalaTestV = "3.2.17"
val scalaCheckV = "1.17.0"
val scalaCheckVshort = scalaCheckV.take(4).replace(".", "-")
val scalaTestPlusV =
"3.2.17.0" // has to match scalatest and scalacheck versions, see https://github.com/scalatest/scalatestplus-scalacheck/releases
// note: Logback 1.3 requires Slf4j 2.x, but Flink has Slf4j 1.7 on its classpath
val logbackV = "1.2.12"
// this is used in cloud, official JsonEncoder uses different field layout
val logbackJsonV = "0.1.5"
val circeV = "0.14.5"
val circeGenericExtrasV = "0.14.3"
val jwtCirceV = "9.3.0"
val jacksonV = "2.14.3"
val catsV = "2.9.0"
val catsEffectV = "3.5.2"
val everitSchemaV = "1.14.2"
val slf4jV = "1.7.36"
val scalaLoggingV = "3.9.5"
val scalaCompatV = "1.0.2"
val ficusV = "1.4.7"
val configV = "1.4.2"
//we want to use 5.x for lite metrics to have tags, however dropwizard development kind of freezed. Maybe we should consider micrometer?
//In Flink metrics we use bundled dropwizard metrics v. 3.x
// rc16+ depend on slf4j 2.x
val dropWizardV = "5.0.0-rc15"
val scalaCollectionsCompatV = "2.10.0"
val testContainersScalaV = "0.40.17"
val testContainersJavaV = "1.18.3"
val nettyV = "4.1.93.Final"
val nettyReactiveStreamsV = "2.0.8"
val akkaV = "2.6.20"
val akkaHttpV = "10.2.10"
val akkaManagementV = "1.1.4"
val akkaHttpCirceV = "1.39.2"
val slickV = "3.4.1"
val slickPgV = "0.21.1"
val hikariCpV = "5.0.1"
val hsqldbV = "2.7.2"
val postgresV = "42.6.0"
val flywayV = "9.19.1"
val confluentV = "7.3.2"
val azureKafkaSchemaRegistryV = "1.1.0-beta.1"
val azureSchemaRegistryV = "1.3.6"
val azureIdentityV = "1.9.0"
val bcryptV = "0.10.2"
val cronParserV = "9.1.6" // 9.1.7+ requires JDK 16+
val javaxValidationApiV = "2.0.1.Final"
val caffeineCacheV = "3.1.6"
val sttpV = "3.8.15"
val tapirV = "1.7.4"
//we use legacy version because this one supports Scala 2.12
val monocleV = "2.1.0"
val jmxPrometheusJavaagentV = "0.18.0"
val wireMockV = "2.35.0"
val findBugsV = "3.0.2"
// depending on scala version one of this jar lays in Flink lib dir
def flinkLibScalaDeps(scalaVersion: String, configurations: Option[String] = None) = forScalaVersion(
scalaVersion,
Seq(),
(2, 12) -> Seq(
"org.apache.flink" %% "flink-scala" % flinkV
), // we basically need only `org.apache.flink.runtime.types.FlinkScalaKryoInstantiator` from it...
(2, 13) -> Seq(
"pl.touk" %% "flink-scala-2-13" % "1.1.1"
) // our tiny custom module with scala 2.13 `org.apache.flink.runtime.types.FlinkScalaKryoInstantiator` impl
).map(m => configurations.map(m % _).getOrElse(m)).map(_ exclude ("com.esotericsoftware", "kryo-shaded"))
lazy val commonDockerSettings = {
Seq(
dockerBaseImage := forScalaVersion(
scalaVersion.value,
"eclipse-temurin:17-jre-jammy",
(
2,
12
) -> "eclipse-temurin:11-jre-jammy" // jre11, cause for jdk17 minimum scala version is 2.12.15, we use 2.12.10
),
dockerUsername := dockerUserName,
dockerUpdateLatest := dockerUpLatestFromProp.getOrElse(!isSnapshot.value),
dockerBuildxPlatforms := Seq("linux/amd64", "linux/arm64"), // not used in case of Docker/publishLocal
dockerAliases := {
// https://docs.docker.com/engine/reference/commandline/tag/#extended-description
def sanitize(str: String) = str.replaceAll("[^a-zA-Z0-9._-]", "_")
val alias = dockerAlias.value
val updateLatest = if (dockerUpdateLatest.value) Some("latest") else None
val updateBranchLatest = if (dockerUpBranchLatestFromProp) {
// TODO: handle it more nicely, checkout actions in CI are not checking out actual branch
// other option would be to reset source branch to checkout out commit
val currentBranch = sys.env.getOrElse("GIT_SOURCE_BRANCH", git.gitCurrentBranch.value)
Some(currentBranch + "-latest")
} else {
None
}
val dockerVersion = Some(version.value)
val tags = List(dockerVersion, updateLatest, updateBranchLatest, dockerTagName).flatten
val scalaSuffix = s"_scala-${CrossVersion.binaryScalaVersion(scalaVersion.value)}"
val tagsWithScalaSuffix = tags.map(t => s"$t$scalaSuffix")
(tagsWithScalaSuffix ++ tags.filter(_ => scalaVersion.value == defaultScalaV))
.map(tag => alias.withTag(Some(sanitize(tag))))
.distinct
}
)
}
lazy val distDockerSettings = {
val nussknackerDir = "/opt/nussknacker"
commonDockerSettings ++ Seq(
dockerBaseImage := "eclipse-temurin:11-jre-jammy", // designer should run on java11 since it may run Flink in-memory-cluster, which does not support newer java
dockerEntrypoint := Seq(s"$nussknackerDir/bin/nussknacker-entrypoint.sh"),
dockerExposedPorts := Seq(dockerPort),
dockerEnvVars := Map(
"HTTP_PORT" -> dockerPort.toString
),
packageName := dockerPackageName,
dockerLabels := Map(
"version" -> version.value,
"scala" -> scalaVersion.value,
"flink" -> flinkV
),
dockerExposedVolumes := Seq(s"$nussknackerDir/storage", s"$nussknackerDir/data"),
Docker / defaultLinuxInstallLocation := nussknackerDir
)
}
val publishAssemblySettings = List(
Compile / assembly / artifact := {
val art = (Compile / assembly / artifact).value
art.withClassifier(Some("assembly"))
},
addArtifact(Compile / assembly / artifact, assembly)
)
def assemblySettings(
assemblyName: String,
includeScala: Boolean,
filterProvidedDeps: Boolean = true
): List[Def.SettingsDefinition] = {
// This work around need to be optional because for designer module it causes excluding of scala lib (because we has there other work around for Idea classpath and provided deps)
val filterProvidedDepsSettingOpt = if (filterProvidedDeps) {
Some(
// For some reason problem described in https://github.com/sbt/sbt-assembly/issues/295 appears, workaround also works...
assembly / fullClasspath := {
val cp = (assembly / fullClasspath).value
val providedDependencies = update.map(f => f.select(configurationFilter("provided"))).value
cp filter { f =>
!providedDependencies.contains(f.data)
}
}
)
} else {
None
}
List(
assembly / assemblyJarName := assemblyName,
assembly / assemblyOption := (assembly / assemblyOption).value.withIncludeScala(includeScala).withLevel(Level.Info),
assembly / assemblyMergeStrategy := modelMergeStrategy,
assembly / test := {}
) ++ filterProvidedDepsSettingOpt
}
def assemblyNoScala(assemblyName: String): List[Def.SettingsDefinition] =
assemblySettings(assemblyName, includeScala = false)
lazy val componentArtifacts = taskKey[List[(File, String)]]("component artifacts")
componentArtifacts := {
List(
(flinkBaseComponents / assembly).value -> "components/flink/flinkBase.jar",
(flinkKafkaComponents / assembly).value -> "components/flink/flinkKafka.jar",
(liteBaseComponents / assembly).value -> "components/lite/liteBase.jar",
(liteKafkaComponents / assembly).value -> "components/lite/liteKafka.jar",
(liteRequestResponseComponents / assembly).value -> "components/lite/liteRequestResponse.jar",
(openapiComponents / assembly).value -> "components/common/openapi.jar",
(sqlComponents / assembly).value -> "components/common/sql.jar"
)
}
lazy val modelArtifacts = taskKey[List[(File, String)]]("model artifacts")
modelArtifacts := {
List(
(defaultModel / assembly).value -> "model/defaultModel.jar",
(flinkExecutor / assembly).value -> "model/flinkExecutor.jar",
)
}
lazy val devArtifacts = taskKey[List[(File, String)]]("dev artifacts")
devArtifacts := {
modelArtifacts.value ++ List(
(flinkDevModel / assembly).value -> "model/devModel.jar",
(devPeriodicDM / assembly).value -> "managers/devPeriodicDM.jar"
)
}
lazy val managerArtifacts = taskKey[List[(File, String)]]("manager artifacts")
managerArtifacts := {
List(
(flinkDeploymentManager / assembly).value -> "managers/nussknacker-flink-manager.jar",
(liteK8sDeploymentManager / assembly).value -> "managers/lite-k8s-manager.jar",
(liteEmbeddedDeploymentManager / assembly).value -> "managers/lite-embedded-manager.jar"
)
}
lazy val dist = sbt
.Project("dist", file("nussknacker-dist"))
.settings(commonSettings)
.enablePlugins(JavaAgent, SbtNativePackager, JavaServerAppPackaging)
.settings(
Universal / packageName := ("nussknacker" + "-" + version.value),
Universal / mappings ++= (root / managerArtifacts).value
++ (root / componentArtifacts).value
++ (if (addDevArtifacts)
Seq((developmentTestsDeploymentManager / assembly).value -> "managers/development-tests-manager.jar")
else Nil)
++ (if (addDevArtifacts) (root / devArtifacts).value: @sbtUnchecked
else (root / modelArtifacts).value: @sbtUnchecked)
++ (flinkExecutor / additionalBundledArtifacts).value,
Universal / packageZipTarball / mappings := {
val universalMappings = (Universal / mappings).value
// we don't want docker-* stuff in .tgz
universalMappings filterNot { case (file, _) =>
file.getName.startsWith("docker-") || file.getName.contains("entrypoint.sh")
}
},
publishArtifact := false,
javaAgents += JavaAgent("io.prometheus.jmx" % "jmx_prometheus_javaagent" % jmxPrometheusJavaagentV % "dist"),
SettingsHelper.makeDeploymentSettings(Universal, Universal / packageZipTarball, "tgz")
)
.settings(distDockerSettings)
.dependsOn(designer)
def engine(name: String) = file(s"engine/$name")
def flink(name: String) = engine(s"flink/$name")
def lite(name: String) = engine(s"lite/$name")
def development(name: String) = engine(s"development/$name")
def component(name: String) = file(s"components/$name")
def utils(name: String) = file(s"utils/$name")
def itSettings() = {
Defaults.itSettings ++ Seq(IntegrationTest / testOptions += scalaTestReports)
}
lazy val requestResponseRuntime = (project in lite("request-response/runtime"))
.settings(commonSettings)
.settings(
name := "nussknacker-request-response-runtime",
libraryDependencies ++= {
Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
"com.typesafe.akka" %% "akka-stream" % akkaV,
"com.typesafe.akka" %% "akka-testkit" % akkaV % "test",
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % "test"
)
}
)
.dependsOn(
liteEngineRuntime,
requestResponseComponentsApi,
httpUtils % "provided",
testUtils % "test",
componentsUtils % "test",
requestResponseComponentsUtils % "test",
liteBaseComponents % "test",
liteRequestResponseComponents % "test"
)
lazy val flinkDeploymentManager = (project in flink("management"))
.configs(IntegrationTest)
.settings(commonSettings)
.settings(itSettings())
.settings(assemblyNoScala("nussknacker-flink-manager.jar"): _*)
.settings(publishAssemblySettings: _*)
.settings(
name := "nussknacker-flink-manager",
IntegrationTest / Keys.test := (IntegrationTest / Keys.test)
.dependsOn(
flinkExecutor / Compile / assembly,
flinkDevModel / Compile / assembly,
flinkDevModelJava / Compile / assembly,
flinkBaseComponents / Compile / assembly,
flinkKafkaComponents / Compile / assembly
)
.value,
// flink cannot run tests and deployment concurrently
IntegrationTest / parallelExecution := false,
libraryDependencies ++= {
Seq(
"org.typelevel" %% "cats-core" % catsV % "provided",
"org.apache.flink" % "flink-streaming-java" % flinkV % flinkScope
excludeAll (
ExclusionRule("log4j", "log4j"),
ExclusionRule("org.slf4j", "slf4j-log4j12"),
ExclusionRule("com.esotericsoftware", "kryo-shaded"),
),
"org.apache.flink" % "flink-statebackend-rocksdb" % flinkV % flinkScope,
"com.softwaremill.retry" %% "retry" % "0.3.6",
"com.dimafeng" %% "testcontainers-scala-scalatest" % testContainersScalaV % "it,test",
"com.dimafeng" %% "testcontainers-scala-kafka" % testContainersScalaV % "it,test",
"com.github.tomakehurst" % "wiremock-jre8" % wireMockV % Test
) ++ flinkLibScalaDeps(scalaVersion.value, Some(flinkScope))
},
// override scala-collection-compat from com.softwaremill.retry:retry
dependencyOverrides += "org.scala-lang.modules" %% "scala-collection-compat" % scalaCollectionsCompatV
)
.dependsOn(
deploymentManagerApi % "provided",
interpreter % "provided",
componentsApi % "provided",
httpUtils % "provided",
flinkScalaUtils % "provided",
kafkaTestUtils % "it,test"
)
lazy val flinkPeriodicDeploymentManager = (project in flink("management/periodic"))
.settings(commonSettings)
.settings(assemblyNoScala("nussknacker-flink-periodic-manager.jar"): _*)
.settings(
name := "nussknacker-flink-periodic-manager",
libraryDependencies ++= {
Seq(
"org.typelevel" %% "cats-core" % catsV % "provided",
"com.typesafe.slick" %% "slick" % slickV % "provided",
"com.typesafe.slick" %% "slick-hikaricp" % slickV % "provided, test",
"com.github.tminglei" %% "slick-pg" % slickPgV,
"org.hsqldb" % "hsqldb" % hsqldbV % "test",
"org.flywaydb" % "flyway-core" % flywayV % "provided",
"com.cronutils" % "cron-utils" % cronParserV,
"com.typesafe.akka" %% "akka-actor" % akkaV,
"com.typesafe.akka" %% "akka-testkit" % akkaV % "test",
"com.dimafeng" %% "testcontainers-scala-scalatest" % testContainersScalaV % "test",
"com.dimafeng" %% "testcontainers-scala-postgresql" % testContainersScalaV % "test",
)
}
)
.dependsOn(
flinkDeploymentManager,
deploymentManagerApi % "provided",
interpreter % "provided",
componentsApi % "provided",
httpUtils % "provided",
testUtils % "test"
)
lazy val flinkDevModel = (project in flink("management/dev-model"))
.settings(commonSettings)
.settings(assemblyNoScala("devModel.jar"): _*)
.settings(
name := "nussknacker-flink-dev-model",
libraryDependencies ++= {
Seq(
"com.cronutils" % "cron-utils" % cronParserV,
"javax.validation" % "validation-api" % javaxValidationApiV,
"org.apache.flink" % "flink-streaming-java" % flinkV % "provided",
"org.apache.flink" % "flink-runtime" % flinkV % "compile" classifier "tests"
)
}
)
.dependsOn(
flinkSchemedKafkaComponentsUtils,
flinkComponentsUtils % Provided,
// We use some components for testing with embedded engine, because of that we need dependency to this api
liteComponentsApi,
componentsUtils,
// TODO: NodeAdditionalInfoProvider & ComponentExtractor should probably be moved to API?
interpreter % "provided",
flinkExecutor % "test",
flinkTestUtils % "test",
kafkaTestUtils % "test"
)
lazy val flinkDevModelJava = (project in flink("management/dev-model-java"))
.settings(commonSettings)
.settings(assemblyNoScala("devModelJava.jar"): _*)
.settings(
name := "nussknacker-flink-dev-model-java",
libraryDependencies ++= {
Seq(
"org.scala-lang.modules" %% "scala-java8-compat" % scalaCompatV,
"org.apache.flink" % "flink-streaming-java" % flinkV % "provided"
)
}
)
.dependsOn(flinkComponentsUtils % Provided, componentsUtils)
lazy val devPeriodicDM = (project in flink("management/dev-periodic-dm"))
.settings(commonSettings)
.settings(assemblyNoScala("devPeriodicDm.jar"): _*)
.settings(
name := "nussknacker-dev-periodic-dm",
libraryDependencies ++= {
Seq(
)
}
)
.dependsOn(flinkPeriodicDeploymentManager, deploymentManagerApi % "provided")
lazy val flinkTests = (project in flink("tests"))
.settings(commonSettings)
.settings(
name := "nussknacker-flink-tests",
libraryDependencies ++= {
Seq(
"org.apache.flink" % "flink-streaming-java" % flinkV % "provided",
"org.apache.flink" % "flink-statebackend-rocksdb" % flinkV % "provided"
)
}
)
.dependsOn(
defaultModel % "test",
flinkExecutor % "test",
flinkKafkaComponents % "test",
flinkBaseComponents % "test",
flinkTestUtils % "test",
kafkaTestUtils % "test",
// for local development
designer % "test",
deploymentManagerApi % "test"
)
lazy val defaultModel = (project in (file("defaultModel")))
.settings(commonSettings)
.settings(assemblyNoScala("defaultModel.jar"): _*)
.settings(publishAssemblySettings: _*)
.settings(
name := "nussknacker-default-model"
)
.dependsOn(defaultHelpers, extensionsApi % Provided)
lazy val flinkExecutor = (project in flink("executor"))
.settings(commonSettings)
.settings(itSettings())
.settings(assemblyNoScala("flinkExecutor.jar"): _*)
.settings(publishAssemblySettings: _*)
.settings(
name := "nussknacker-flink-executor",
IntegrationTest / Keys.test := (IntegrationTest / Keys.test)
.dependsOn(
ThisScope / prepareItLibs
)
.value,
libraryDependencies ++= {
Seq(
"org.apache.flink" % "flink-streaming-java" % flinkV % "provided",
"org.apache.flink" % "flink-runtime" % flinkV % "provided",
"org.apache.flink" % "flink-statebackend-rocksdb" % flinkV % "provided",
"org.apache.flink" % "flink-metrics-dropwizard" % flinkV % "provided",
)
},
prepareItLibs := {
val workTarget = (ThisScope / baseDirectory).value / "target" / "it-libs"
val artifacts = (ThisScope / additionalBundledArtifacts).value
IO.copy(artifacts.map { case (source, target) => (source, workTarget / target) })
},
additionalBundledArtifacts := {
createClasspathBasedMapping(
(Compile / managedClasspath).value,
"org.apache.flink",
"flink-metrics-dropwizard",
"flink-dropwizard-metrics-deps/flink-metrics-dropwizard.jar"
) ++
createClasspathBasedMapping(
(Compile / managedClasspath).value,
"io.dropwizard.metrics",
"metrics-core",
"flink-dropwizard-metrics-deps/dropwizard-metrics-core.jar"
)
}.toList,
)
.dependsOn(flinkComponentsUtils, interpreter, flinkExtensionsApi, flinkTestUtils % "test")
lazy val interpreter = (project in file("interpreter"))
.settings(commonSettings)
.settings(
name := "nussknacker-interpreter",
libraryDependencies ++= {
Seq(
"org.typelevel" %% "cats-effect" % catsEffectV,
"org.scala-lang.modules" %% "scala-java8-compat" % scalaCompatV,
"org.apache.avro" % "avro" % avroV % "test",
"org.scalacheck" %% "scalacheck" % scalaCheckV % "test",
"com.cronutils" % "cron-utils" % cronParserV % "test",
"org.scalatestplus" %% s"scalacheck-$scalaCheckVshort" % scalaTestPlusV % "test"
)
}
)
.dependsOn(utilsInternal, mathUtils, testUtils % "test", componentsUtils % "test")
lazy val benchmarks = (project in file("benchmarks"))
.settings(commonSettings)
.enablePlugins(JmhPlugin)
.settings(
name := "nussknacker-benchmarks",
libraryDependencies ++= {
Seq(
"org.apache.flink" % "flink-streaming-java" % flinkV exclude ("com.esotericsoftware", "kryo-shaded"),
"org.apache.flink" % "flink-runtime" % flinkV
)
},
Jmh / run / javaOptions ++= (
if (System.getProperty("os.name").startsWith("Windows")) {
// Allow long classpath on Windows, JMH requires that classpath and temp directory have common root path,
// so we're always setting it in sbt's target directory (https://github.com/sbt/sbt-jmh/issues/241)
Seq("-Djmh.separateClasspathJAR=true", "\"-Djava.io.tmpdir=" + target.value + "\"")
} else
Seq.empty
),
// To avoid Intellij message that jmh generated classes are shared between main and test
Jmh / classDirectory := (Test / classDirectory).value,
Jmh / dependencyClasspath := (Test / dependencyClasspath).value,
Jmh / generateJmhSourcesAndResources := (Jmh / generateJmhSourcesAndResources).dependsOn(Test / compile).value,
)
.dependsOn(
designer,
extensionsApi,
interpreter,
flinkSchemedKafkaComponentsUtils,
flinkExecutor,
flinkBaseComponents,
testUtils % "test"
)
lazy val kafkaUtils = (project in utils("kafka-utils"))
.settings(commonSettings)
.settings(
name := "nussknacker-kafka-utils",
libraryDependencies ++= {
Seq(
"org.apache.kafka" % "kafka-clients" % kafkaV
)
}
// Depends on componentsApi because of dependency to NuExceptionInfo and NonTransientException -
// lite kafka engine handles component exceptions in runtime part
)
.dependsOn(commonUtils % Provided, componentsApi % Provided)
lazy val kafkaComponentsUtils = (project in utils("kafka-components-utils"))
.configs(IntegrationTest)
.settings(commonSettings)
.settings(itSettings())
.settings(
name := "nussknacker-kafka-components-utils",
libraryDependencies ++= {
Seq(
"javax.validation" % "validation-api" % javaxValidationApiV,
"com.dimafeng" %% "testcontainers-scala-scalatest" % testContainersScalaV % "it",
"com.dimafeng" %% "testcontainers-scala-kafka" % testContainersScalaV % "it"
)
}
)
.dependsOn(kafkaUtils, componentsUtils % Provided, componentsApi % Provided, testUtils % "it, test")
lazy val schemedKafkaComponentsUtils = (project in utils("schemed-kafka-components-utils"))
.configs(ExternalDepsTests)
.settings(externalDepsTestsSettings)
.settings(commonSettings)
.settings(
name := "nussknacker-schemed-kafka-components-utils",
libraryDependencies ++= {
Seq(
"io.confluent" % "kafka-json-schema-provider" % confluentV excludeAll (
ExclusionRule("log4j", "log4j"),
ExclusionRule("org.slf4j", "slf4j-log4j12"),
),
"io.confluent" % "kafka-avro-serializer" % confluentV excludeAll (
ExclusionRule("log4j", "log4j"),
ExclusionRule("org.slf4j", "slf4j-log4j12")
),
"com.microsoft.azure" % "azure-schemaregistry-kafka-avro" % azureKafkaSchemaRegistryV excludeAll (
ExclusionRule("com.azure", "azure-core-http-netty")
),
"com.azure" % "azure-data-schemaregistry" % azureSchemaRegistryV excludeAll (
ExclusionRule("com.azure", "azure-core-http-netty")
),
"com.azure" % "azure-identity" % azureIdentityV excludeAll (
ExclusionRule("com.azure", "azure-core-http-netty")
),
// we use azure-core-http-okhttp instead of azure-core-http-netty to avoid netty version collisions
// TODO: switch to jdk implementation after releasing it: https://github.com/Azure/azure-sdk-for-java/issues/27065
"com.azure" % "azure-core-http-okhttp" % "1.11.9",
// it is workaround for missing VerifiableProperties class - see https://github.com/confluentinc/schema-registry/issues/553
"org.apache.kafka" %% "kafka" % kafkaV % "provided" excludeAll (
ExclusionRule("log4j", "log4j"),
ExclusionRule("org.slf4j", "slf4j-log4j12")
),
"tech.allegro.schema.json2avro" % "converter" % "0.2.15",
"org.scala-lang.modules" %% "scala-collection-compat" % scalaCollectionsCompatV,
"org.scalatest" %% "scalatest" % scalaTestV % "test"
)
},
)
.dependsOn(componentsUtils % Provided, kafkaComponentsUtils, interpreter % "test", kafkaTestUtils % "test", jsonUtils)
lazy val flinkSchemedKafkaComponentsUtils = (project in flink("schemed-kafka-components-utils"))
.settings(commonSettings)
.settings(
name := "nussknacker-flink-schemed-kafka-components-utils",
libraryDependencies ++= {
Seq(
"org.apache.flink" % "flink-streaming-java" % flinkV % "provided",
"org.apache.flink" % "flink-avro" % flinkV,
"org.apache.flink" % s"flink-connector-kafka" % flinkV % "test",
"org.scalatest" %% "scalatest" % scalaTestV % "test"
)
}
)
.dependsOn(
schemedKafkaComponentsUtils % "compile;test->test",
flinkKafkaComponentsUtils,
flinkExtensionsApi % Provided,
flinkComponentsUtils % Provided,
componentsUtils % Provided,
kafkaTestUtils % "test",
flinkTestUtils % "test",
flinkExecutor % "test"
)
lazy val flinkKafkaComponentsUtils = (project in flink("kafka-components-utils"))
.settings(commonSettings)
.settings(
name := "nussknacker-flink-kafka-components-utils",
libraryDependencies ++= {
Seq(
"org.apache.flink" % "flink-connector-kafka" % flinkV,
"org.apache.flink" % "flink-streaming-java" % flinkV % "provided",
"org.scalatest" %% "scalatest" % scalaTestV % "test"
)
}
)
.dependsOn(
componentsApi % Provided,
kafkaComponentsUtils,
flinkComponentsUtils % Provided,
componentsUtils % Provided,
flinkExecutor % "test",
kafkaTestUtils % "test",
flinkTestUtils % "test"
)
lazy val kafkaTestUtils = (project in utils("kafka-test-utils"))
.settings(commonSettings)
.settings(
name := "nussknacker-kafka-test-utils",
libraryDependencies ++= {
Seq(
"org.apache.kafka" %% "kafka" % kafkaV excludeAll (
ExclusionRule("log4j", "log4j"),
ExclusionRule("org.slf4j", "slf4j-log4j12")
),
"org.slf4j" % "log4j-over-slf4j" % slf4jV
)
}
)
.dependsOn(testUtils, kafkaUtils, commonUtils % Provided)
// This module:
// - should not be a dependant of runtime (interpreter, flinkExecutor, *Runtime modules) production code
// - should not be a dependant of designer production code
// - can be a provided dependant of component extensions
// - should be a compile/runtime dependant of defaultModel module
// Thanks to that, it will be provided in one place, and will be visible in compilation which classes are part of root API and which of utils
lazy val componentsUtils = (project in utils("components-utils"))
.settings(commonSettings)
.settings(
name := "nussknacker-components-utils",
libraryDependencies ++= forScalaVersion(
scalaVersion.value,
Seq(),
(2, 13) -> Seq("org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4" % Test)
)
)