-
Notifications
You must be signed in to change notification settings - Fork 93
/
build.sbt
2294 lines (2140 loc) · 97.2 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
val scala212 = "2.12.10"
val scala213 = "2.13.15"
lazy val defaultScalaV = sys.env.get("NUSSKNACKER_SCALA_VERSION") match {
case None | Some("2.13") => scala213
case Some("2.12") => scala212
case Some(unsupported) => throw new IllegalArgumentException(s"Nu doesn't support $unsupported Scala version")
}
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 requires Scala 2.12.11+
// 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.19"
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 defaultMergeStrategy: String => MergeStrategy = {
// remove JPMS module descriptors (a proper soultion would be to merge them)
case PathList(ps @ _*) if ps.last == "module-info.class" => MergeStrategy.discard
// we override Spring's class and we want to keep only our implementation
case PathList(ps @ _*) if ps.last == "NumberUtils.class" => MergeStrategy.first
// merge Netty version information files
case PathList(ps @ _*) if ps.last == "io.netty.versions.properties" => MergeStrategy.concat
// due to swagger-parser dependencies having different schema definitions (json-schema-validator and json-schema-core)
case PathList("draftv4", "schema") => MergeStrategy.first
case x => MergeStrategy.defaultMergeStrategy(x)
}
def designerMergeStrategy: String => MergeStrategy = {
// https://tapir.softwaremill.com/en/latest/docs/openapi.html#using-swaggerui-with-sbt-assembly
case PathList("META-INF", "maven", "org.webjars", "swagger-ui", "pom.properties") =>
MergeStrategy.singleOrError
case x => 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)(provide: PartialFunction[(Int, Int), T]): T = {
CrossVersion.partialVersion(version) match {
case Some((major, minor)) if provide.isDefinedAt((major.toInt, minor.toInt)) =>
provide((major.toInt, minor.toInt))
case Some(_) =>
throw new IllegalArgumentException(s"Scala version $version is not handled")
case None =>
throw new IllegalArgumentException(s"Invalid Scala version $version")
}
}
lazy val commonSettings =
publishSettings ++
Seq(
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.3" cross CrossVersion.full),
libraryDependencies += compilerPlugin(
"com.github.ghik" % "silencer-plugin" % forScalaVersion(scalaVersion.value) {
case (2, 12) => silencerV_2_12
case _ => silencerV
} cross CrossVersion.full
),
libraryDependencies ++= forScalaVersion(scalaVersion.value) {
case (2, 12) => Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full))
case _ => Seq()
},
scalacOptions := Seq(
"-unchecked",
"-deprecation",
"-encoding",
"utf8",
"-Xfatal-warnings",
"-feature",
"-language:postfixOps",
"-language:existentials",
"-release",
"11"
) ++ forScalaVersion(scalaVersion.value) {
case (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",
)
case (2, 13) =>
Seq(
"-Ymacro-annotations"
)
},
Compile / compile / 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"
),
// 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) {
case (2, 12) => silencerV_2_12
case _ => silencerV
} % Provided cross CrossVersion.full
),
// here we add dependencies that we want to have fixed across all modules
dependencyOverrides ++= Seq(
"org.apache.avro" % "avro" % avroV,
"com.typesafe" % "config" % configV,
"commons-io" % "commons-io" % flinkCommonsIOV, // dependency of avro via commons-compress
"org.apache.commons" % "commons-compress" % flinkCommonsCompressV, // dependency of avro
"org.apache.commons" % "commons-text" % flinkCommonsTextV, // dependency of commons-lang3, avro via commons-compress
"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.19.1"
val flinkConnectorKafkaV = "3.2.0-1.19"
val flinkCommonsCompressV = "1.26.0"
val flinkCommonsLang3V = "3.12.0"
val flinkCommonsTextV = "1.10.0"
val flinkCommonsIOV = "2.15.1"
val avroV = "1.11.4"
//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.8.1"
//TODO: Spring 5.3 has some problem with handling our PrimitiveOrWrappersPropertyAccessor
val springV = "5.2.23.RELEASE"
val scalaTestV = "3.2.18"
val scalaCheckV = "1.17.1"
val scalaCheckVshort = scalaCheckV.take(4).replace(".", "-")
val scalaTestPlusV =
"3.2.18.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.13"
// this is used in cloud, official JsonEncoder uses different field layout
val logbackJsonV = "0.1.5"
val betterFilesV = "3.9.2"
val circeV = "0.14.10"
val circeGenericExtrasV = "0.14.4"
val circeYamlV = "0.15.2" // 0.15.3 drops Scala 2.12
val jwtCirceV = "10.0.1"
val jacksonV = "2.17.2"
val catsV = "2.12.0"
val catsEffectV = "3.5.4"
val everitSchemaV = "1.14.4"
val slf4jV = "1.7.36"
val scalaLoggingV = "3.9.5"
val scalaCompatV = "1.0.2"
val ficusV = "1.4.7"
val configV = "1.4.3"
//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.12.0"
val testContainersScalaV = "0.41.4"
val testContainersJavaV = "1.20.1"
val nettyV = "4.1.113.Final"
val nettyReactiveStreamsV = "2.0.12"
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" // 3.5 drops Scala 2.12
val slickPgV = "0.21.1" // 0.22.2 uses Slick 3.5
val hikariCpV = "5.1.0"
val hsqldbV = "2.7.3"
val postgresV = "42.7.4"
// Flway 10 requires Java 17
val flywayV = "9.22.3"
val confluentV = "7.5.1"
val azureKafkaSchemaRegistryV = "1.1.1"
val azureSchemaRegistryV = "1.4.9"
val azureIdentityV = "1.13.3"
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.8"
val sttpV = "3.9.8"
val tapirV = "1.11.7"
val openapiCirceYamlV = "0.11.3"
//we use legacy version because this one supports Scala 2.12
val monocleV = "2.1.0"
val jmxPrometheusJavaagentV = "0.20.0"
val wireMockV = "3.9.1"
val findBugsV = "3.0.2"
val enumeratumV = "1.7.4"
val ujsonV = "4.0.1"
val igniteV = "2.10.0"
val retryV = "0.3.6"
// depending on scala version one of this jar lays in Flink lib dir
def flinkLibScalaDeps(scalaVersion: String, configurations: Option[String] = None) = forScalaVersion(scalaVersion) {
case (2, 12) =>
Seq(
"org.apache.flink" %% "flink-scala" % flinkV
) // we basically need only `org.apache.flink.runtime.types.FlinkScalaKryoInstantiator` from it...
case (2, 13) =>
Seq(
"pl.touk" %% "flink-scala-2-13" % "1.1.2"
) // 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(
// designer should run on java11 since it may run Flink in-memory-cluster, which does not support newer java and we want to have same jre in both designer and lite-runner
// to make analysis of problems with jre compatibility easier using testing mechanism and embedded server
// TODO: we want to support jre17+ but before that flink must be compatible with jre17+ and we should handle opening of modules for spel reflectional access to java modules classes
dockerBaseImage := "eclipse-temurin:11-jre-jammy",
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(
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 := defaultMergeStrategy
) ++ filterProvidedDepsSettingOpt
}
def assemblyNoScala(assemblyName: String): List[Def.SettingsDefinition] =
assemblySettings(assemblyName, includeScala = false)
lazy val componentArtifacts = taskKey[List[(File, String)]]("component artifacts")
lazy val modelArtifacts = taskKey[List[(File, String)]]("model artifacts")
lazy val devArtifacts = taskKey[List[(File, String)]]("dev artifacts")
lazy val managerArtifacts = taskKey[List[(File, String)]]("manager artifacts")
def filterDevConfigArtifacts(files: Seq[(File, String)]) = {
val devConfigFiles = Set("dev-tables-definition.sql", "dev-application.conf", "dev-oauth2-users.conf")
files.filterNot { case (file, _) => devConfigFiles.contains(file.getName) }
}
lazy val distribution: Project = sbt
.Project("dist", file("nussknacker-dist"))
.settings(commonSettings)
.enablePlugins(JavaAgent, SbtNativePackager, JavaServerAppPackaging)
.settings(
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",
)
},
componentArtifacts := {
List(
(flinkBaseComponents / assembly).value -> "components/flink/flinkBase.jar",
(flinkBaseUnboundedComponents / assembly).value -> "components/flink/flinkBaseUnbounded.jar",
(flinkKafkaComponents / assembly).value -> "components/flink/flinkKafka.jar",
(flinkTableApiComponents / assembly).value -> "components/flink-table/flinkTable.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",
)
},
modelArtifacts := {
List(
(defaultModel / assembly).value -> "model/defaultModel.jar",
(flinkExecutor / assembly).value -> "model/flinkExecutor.jar",
)
},
devArtifacts := {
modelArtifacts.value ++ List(
(flinkDevModel / assembly).value -> "model/devModel.jar",
(flinkPeriodicDeploymentManager / assembly).value -> "managers/nussknacker-flink-periodic-manager.jar",
)
},
Universal / packageName := ("nussknacker" + "-" + version.value),
Universal / mappings := {
val universalMappingsWithDevConfigFilter =
if (addDevArtifacts) (Universal / mappings).value
else filterDevConfigArtifacts((Universal / mappings).value)
universalMappingsWithDevConfigFilter ++
(managerArtifacts).value ++
(componentArtifacts).value ++
(if (addDevArtifacts)
Seq((developmentTestsDeploymentManager / assembly).value -> "managers/development-tests-manager.jar")
else Nil) ++
(if (addDevArtifacts) (devArtifacts).value: @sbtUnchecked
else (modelArtifacts).value: @sbtUnchecked) ++
(flinkExecutor / additionalBundledArtifacts).value
},
Universal / packageZipTarball / mappings := {
val universalMappingsWithDevConfigFilter =
if (addDevArtifacts) (Universal / mappings).value
else filterDevConfigArtifacts((Universal / mappings).value)
// we don't want docker-* stuff in .tgz
universalMappingsWithDevConfigFilter 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,
flinkExecutor / prepareItLibs,
flinkDevModel / Compile / assembly,
flinkDevModelJava / Compile / assembly,
flinkTableApiComponents / Compile / assembly,
flinkBaseComponents / Compile / assembly,
flinkBaseUnboundedComponents / 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" % retryV,
"org.wiremock" % "wiremock" % wireMockV % Test,
"org.scalatestplus" %% "mockito-5-10" % scalaTestPlusV % 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,
scenarioCompiler % Provided,
componentsApi % Provided,
httpUtils % Provided,
flinkScalaUtils % Provided,
flinkTestUtils % IntegrationTest,
kafkaTestUtils % "it,test"
)
lazy val flinkPeriodicDeploymentManager = (project in flink("management/periodic"))
.settings(commonSettings)
.settings(assemblyNoScala("nussknacker-flink-periodic-manager.jar"): _*)
.settings(publishAssemblySettings: _*)
.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,
scenarioCompiler % Provided,
componentsApi % Provided,
httpUtils % Provided,
testUtils % Test
)
lazy val flinkMetricsDeferredReporter = (project in flink("metrics-deferred-reporter"))
.settings(commonSettings)
.settings(
name := "nussknacker-flink-metrics-deferred-reporter",
crossPaths := false,
libraryDependencies ++= {
Seq(
"org.apache.flink" % "flink-streaming-java" % flinkV % Provided
)
},
)
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(
extensionsApi,
commonComponents,
flinkSchemedKafkaComponentsUtils,
flinkComponentsUtils % Provided,
// We use some components for testing with embedded engine, because of that we need dependency to this api
// It has to be in the default, Compile scope because all components are eagerly loaded so it will be loaded also
// on the Flink side where this library is missing
liteComponentsApi,
componentsUtils % Provided,
// TODO: NodeAdditionalInfoProvider & ComponentExtractor should probably be moved to API?
scenarioCompiler % 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(
extensionsApi,
flinkComponentsUtils % Provided
)
lazy val flinkTests = (project in flink("tests"))
.settings(commonSettings)
.settings(
name := "nussknacker-flink-tests",
libraryDependencies ++= {
Seq(
"org.apache.flink" % "flink-connector-base" % flinkV % Test,
"org.apache.flink" % "flink-streaming-java" % flinkV % Test,
"org.apache.flink" % "flink-statebackend-rocksdb" % flinkV % Test,
"org.apache.flink" % "flink-connector-kafka" % flinkConnectorKafkaV % Test,
"org.apache.flink" % "flink-json" % flinkV % Test
)
}
)
.dependsOn(
defaultModel % Test,
flinkExecutor % Test,
flinkKafkaComponents % Test,
flinkBaseComponents % Test,
flinkBaseUnboundedComponents % Test,
flinkTableApiComponents % Test,
flinkTestUtils % Test,
kafkaTestUtils % Test,
flinkComponentsTestkit % 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",
libraryDependencies ++= {
Seq(
"org.scalatest" %% "scalatest" % scalaTestV % Test
)
}
)
.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,
// This dependency must be provided, because some cloud providers, such as Ververica, already have it on their classpath, which may cause a conflict
"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, scenarioCompiler, flinkExtensionsApi, flinkTestUtils % Test)
lazy val scenarioCompiler = (project in file("scenario-compiler"))
.settings(commonSettings)
.settings(
name := "nussknacker-scenario-compiler",
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(componentsUtils, utilsInternal, mathUtils, testUtils % 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,
"com.dimafeng" %% "testcontainers-scala-scalatest" % testContainersScalaV % Test,
)
},
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,
)
.settings {
// TODO: it'd be better to use scalaVersion here, but for some reason it's hard to disable existing task dynamically
forScalaVersion(defaultScalaV) {
case (2, 12) => doExecuteMainFromTestSources
case (2, 13) => executeMainFromTestSourcesNotSupported
}
}
.dependsOn(
designer,
extensionsApi,
scenarioCompiler % "test->test;test->compile",
flinkSchemedKafkaComponentsUtils,
flinkExecutor,
flinkBaseComponents,
flinkBaseUnboundedComponents,
testUtils % Test
)
lazy val doExecuteMainFromTestSources = Seq(
(Test / runMain) := (Test / runMain)
.dependsOn(distribution / Docker / publishLocal)
.evaluated
)
lazy val executeMainFromTestSourcesNotSupported = Seq(
(Test / runMain) := {
streams.value.log.info(
"E2E benchmarks are skipped for Scala 2.13 because Nu installation example is currently based on Scala 2.12"
)
}
)
lazy val kafkaUtils = (project in utils("kafka-utils"))
.settings(commonSettings)
.settings(
name := "nussknacker-kafka-utils",
libraryDependencies ++= {
Seq(
"org.apache.kafka" % "kafka-clients" % kafkaV,
"org.scalatest" %% "scalatest" % scalaTestV % Test,
)
}
// 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 % IntegrationTest,
"com.dimafeng" %% "testcontainers-scala-kafka" % testContainersScalaV % IntegrationTest
)
}
)
.dependsOn(kafkaUtils, componentsUtils % 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("commons-logging", "commons-logging"),
ExclusionRule("log4j", "log4j"),
ExclusionRule("org.slf4j", "slf4j-log4j12"),
),
"io.confluent" % "kafka-avro-serializer" % confluentV excludeAll (
ExclusionRule("commons-logging", "commons-logging"),
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,
scenarioCompiler % "test->test;test->compile",
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" % "flink-connector-kafka" % flinkConnectorKafkaV % 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" % flinkConnectorKafkaV,