/
build.sbt
435 lines (388 loc) · 15.3 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
import com.typesafe.sbt.SbtNativePackager.autoImport.NativePackagerHelper._
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.{Docker, dockerRepository}
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
import org.knora.Dependencies
import sbt._
import sbt.Keys.version
import sbt.librarymanagement.Resolver
import scala.language.postfixOps
import scala.sys.process.Process
//////////////////////////////////////
// GLOBAL SETTINGS
//////////////////////////////////////
// when true enables run cancellation w/o exiting sbt
// use Ctrl-c to stop current task but not quit SBT
Global / cancelable := true
Global / scalaVersion := Dependencies.ScalaVersion
Global / semanticdbEnabled := true
Global / semanticdbVersion := scalafixSemanticdb.revision
Global / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"
lazy val aggregatedProjects: Seq[ProjectReference] = Seq(webapi, sipi)
lazy val buildSettings = Seq(
organization := "org.knora",
version := (ThisBuild / version).value
)
lazy val rootBaseDir = ThisBuild / baseDirectory
lazy val root: Project = Project(id = "root", file("."))
.aggregate(
webapi,
sipi,
shared,
// user
userCore,
userHandler,
userRepo,
userInterface,
// role
roleCore,
roleHandler,
roleRepo,
roleInterface,
// project
projectCore,
projectHandler,
projectRepo,
projectInterface,
// schema
schemaCore
)
.enablePlugins(GitVersioning, GitBranchPrompt)
.settings(
// values set for all sub-projects
// These are normal sbt settings to configure for release, skip if already defined
Global / onChangedBuildSource := ReloadOnSourceChanges,
ThisBuild / licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
ThisBuild / homepage := Some(url("https://github.com/dasch-swiss/dsp-api")),
ThisBuild / scmInfo := Some(
ScmInfo(url("https://github.com/dasch-swiss/dsp-api"), "scm:git:git@github.com:dasch-swiss/dsp-api.git")
),
Global / scalaVersion := Dependencies.ScalaVersion,
// use 'git describe' for deriving the version
git.useGitDescribe := true,
// override generated version string because docker hub rejects '+' in tags
ThisBuild / version ~= (_.replace('+', '-')),
publish / skip := true,
name := "dsp-api"
)
addCommandAlias("fmt", "; all root/scalafmtSbt root/scalafmtAll; root/scalafixAll")
addCommandAlias("check", "; all root/scalafmtSbtCheck root/scalafmtCheckAll; root/scalafixAll --check")
lazy val customScalacOptions = Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations",
"-Wunused"
)
//////////////////////////////////////
// DSP's custom SIPI
//////////////////////////////////////
lazy val sipi: Project = Project(id = "sipi", base = file("sipi"))
.enablePlugins(DockerPlugin)
.settings(
Compile / packageDoc / mappings := Seq(),
Compile / packageSrc / mappings := Seq(),
Docker / dockerRepository := Some("daschswiss"),
Docker / packageName := "knora-sipi",
dockerUpdateLatest := true,
dockerBaseImage := Dependencies.sipiImage,
Docker / maintainer := "support@dasch.swiss",
Docker / dockerExposedPorts ++= Seq(1024),
Docker / defaultLinuxInstallLocation := "/sipi",
Universal / mappings ++= {
// copy the sipi/scripts folder
directory("sipi/scripts"),
},
// use filterNot to return all items that do NOT meet the criteria
dockerCommands := dockerCommands.value.filterNot {
// ExecCmd is a case class, and args is a varargs variable, so you need to bind it with @
// remove ENTRYPOINT
case ExecCmd("ENTRYPOINT", args @ _*) => true
// remove CMD
case ExecCmd("CMD", args @ _*) => true
case Cmd("USER", args @ _*) => true
// don't filter the rest; don't filter out anything that doesn't match a pattern
case cmd => false
}
)
//////////////////////////////////////
// WEBAPI (./webapi)
//////////////////////////////////////
run / connectInput := true
lazy val webApiCommonSettings = Seq(
name := "webapi"
)
lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
.settings(buildSettings)
.enablePlugins(SbtTwirl, JavaAppPackaging, DockerPlugin, GatlingPlugin, JavaAgent, BuildInfoPlugin)
.settings(
name := "webapi",
resolvers ++= Seq(
Resolver.bintrayRepo("hseeberger", "maven"),
"Sonatype" at "https://oss.sonatype.org/content/repositories/snapshots"
),
libraryDependencies ++= Dependencies.webapiLibraryDependencies
)
.settings(
inConfig(Test)(Defaults.testTasks ++ baseAssemblySettings)
)
.settings(
// add needed files to production jar
Compile / packageBin / mappings ++= Seq(
(rootBaseDir.value / "knora-ontologies" / "knora-admin.ttl") -> "knora-ontologies/knora-admin.ttl",
(rootBaseDir.value / "knora-ontologies" / "knora-base.ttl") -> "knora-ontologies/knora-base.ttl",
(rootBaseDir.value / "knora-ontologies" / "salsah-gui.ttl") -> "knora-ontologies/salsah-gui.ttl",
(rootBaseDir.value / "knora-ontologies" / "standoff-data.ttl") -> "knora-ontologies/standoff-data.ttl",
(rootBaseDir.value / "knora-ontologies" / "standoff-onto.ttl") -> "knora-ontologies/standoff-onto.ttl",
(rootBaseDir.value / "webapi" / "scripts" / "fuseki-repository-config.ttl.template") -> "webapi/scripts/fuseki-repository-config.ttl.template" // needed for initialization of triplestore
),
// use packaged jars (through packageBin) on classpaths instead of class directories for production
Compile / exportJars := true,
// add needed files to test jar
Test / packageBin / mappings ++= Seq(
(rootBaseDir.value / "webapi" / "scripts" / "fuseki-repository-config.ttl.template") -> "webapi/scripts/fuseki-repository-config.ttl.template", // needed for initialization of triplestore
(rootBaseDir.value / "sipi" / "config" / "sipi.docker-config.lua") -> "sipi/config/sipi.docker-config.lua"
),
// use packaged jars (through packageBin) on classpaths instead of class directories for test
Test / exportJars := true
)
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations",
// silence twirl templates unused imports warnings
"-Wconf:src=target/.*:s",
"-Wunused:imports"
),
logLevel := Level.Info,
run / javaOptions := webapiJavaRunOptions,
javaAgents += Dependencies.aspectjweaver,
Test / fork := true, // run tests in a forked JVM
Test / testForkedParallel := false, // not run forked tests in parallel
Test / parallelExecution := false, // not run non-forked tests in parallel
// Global / concurrentRestrictions += Tags.limit(Tags.Test, 1), // restrict the number of concurrently executing tests in all projects
Test / javaOptions ++= Seq("-Dconfig.resource=fuseki.conf") ++ webapiJavaTestOptions,
// Test / javaOptions ++= Seq("-Dakka.log-config-on-start=on"), // prints out akka config
// Test / javaOptions ++= Seq("-Dconfig.trace=loads"), // prints out config locations
Test / testOptions += Tests.Argument("-oDF"), // show full stack traces and test case durations
// add test framework for running zio-tests
Test / testFrameworks ++= Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.settings(
// prepare for publishing
// Skip packageDoc and packageSrc task on stage
Compile / packageDoc / mappings := Seq(),
Compile / packageSrc / mappings := Seq(),
// define folders inside container
Universal / mappings ++= {
// copy the scripts folder
directory("webapi/scripts") ++
// add knora-ontologies
directory("knora-ontologies") ++
// copy configuration files to config directory
contentOf("webapi/src/main/resources").toMap.mapValues("config/" + _)
},
// add 'config' directory to the classpath of the start script,
Universal / scriptClasspath := Seq("webapi/scripts", "knora-ontologies", "../config/") ++ scriptClasspath.value,
// need this here, so that the Manifest inside the jars has the correct main class set.
Compile / mainClass := Some("org.knora.webapi.Main"),
// add dockerCommands used to create the image
// docker:stage, docker:publishLocal, docker:publish, docker:clean
Docker / dockerRepository := Some("daschswiss"),
Docker / packageName := "knora-api",
dockerUpdateLatest := true,
dockerBaseImage := "eclipse-temurin:17-jre-focal",
Docker / maintainer := "support@dasch.swiss",
Docker / dockerExposedPorts ++= Seq(3333),
Docker / defaultLinuxInstallLocation := "/opt/docker",
// use filterNot to return all items that do NOT meet the criteria
dockerCommands := dockerCommands.value.filterNot {
// Remove USER command
case Cmd("USER", args @ _*) => true
// don't filter the rest; don't filter out anything that doesn't match a pattern
case cmd => false
}
)
.settings(
buildInfoKeys ++= Seq[BuildInfoKey](
name,
version,
"akkaHttp" -> Dependencies.AkkaHttpVersion,
"sipi" -> Dependencies.sipiImage,
"fuseki" -> Dependencies.fusekiImage
),
buildInfoPackage := "org.knora.webapi.http.version"
)
.dependsOn(shared, schemaCore)
lazy val webapiJavaRunOptions = Seq(
"-Xms1G",
"-Xmx1G",
"-Xss6M"
)
lazy val webapiJavaTestOptions = Seq(
// "-showversion",
"-Xms1G",
"-Xmx1G"
// "-verbose:gc",
// "-XX:+UseG1GC",
// "-XX:MaxGCPauseMillis=500",
// "-XX:MaxMetaspaceSize=4096m"
)
//////////////////////////////////////
// DSP's new codebase
//////////////////////////////////////
// dsp-api-main project
lazy val dspApiMain = project
.in(file("dsp-api-main"))
.settings(
scalacOptions ++= customScalacOptions,
name := "dspApiMain",
libraryDependencies ++= Dependencies.dspApiMainLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(userInterface, userHandler, userRepo)
// Role projects
lazy val roleInterface = project
.in(file("dsp-role/interface"))
.settings(
scalacOptions ++= customScalacOptions,
name := "roleInterface",
libraryDependencies ++= Dependencies.roleInterfaceLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared, roleHandler)
lazy val roleHandler = project
.in(file("dsp-role/handler"))
.settings(
scalacOptions ++= customScalacOptions,
name := "roleHandler",
libraryDependencies ++= Dependencies.roleHandlerLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(
shared,
roleCore % "compile->compile;test->test",
roleRepo % "test->test"
)
lazy val roleRepo = project
.in(file("dsp-role/repo"))
.settings(
scalacOptions ++= customScalacOptions,
name := "roleRepo",
libraryDependencies ++= Dependencies.roleRepoLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared, roleCore % "compile->compile;test->test")
lazy val roleCore = project
.in(file("dsp-role/core"))
.settings(
scalacOptions ++= customScalacOptions,
name := "roleCore",
libraryDependencies ++= Dependencies.roleCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared)
// User projects
lazy val userInterface = project
.in(file("dsp-user/interface"))
.settings(
scalacOptions ++= customScalacOptions,
name := "userInterface",
libraryDependencies ++= Dependencies.userInterfaceLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared % "compile->compile;test->test", userHandler, userRepo % "test->test")
lazy val userHandler = project
.in(file("dsp-user/handler"))
.settings(
scalacOptions ++= customScalacOptions,
name := "userHandler",
libraryDependencies ++= Dependencies.userHandlerLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(
shared % "compile->compile;test->test",
userCore % "compile->compile;test->test",
userRepo % "test->test" // userHandler tests need mock implementation of UserRepo
)
lazy val userRepo = project
.in(file("dsp-user/repo"))
.settings(
scalacOptions ++= customScalacOptions,
name := "userRepo",
libraryDependencies ++= Dependencies.userRepoLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared, userCore % "compile->compile;test->test")
lazy val userCore = project
.in(file("dsp-user/core"))
.settings(
scalacOptions ++= customScalacOptions,
name := "userCore",
libraryDependencies ++= Dependencies.userCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared)
// project projects
lazy val projectInterface = project
.in(file("dsp-project/interface"))
.settings(
scalacOptions ++= customScalacOptions,
name := "projectInterface",
libraryDependencies ++= Dependencies.projectInterfaceLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared, projectHandler)
lazy val projectHandler = project
.in(file("dsp-project/handler"))
.settings(
scalacOptions ++= customScalacOptions,
name := "projectHandler",
libraryDependencies ++= Dependencies.projectHandlerLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(
shared,
projectCore,
projectRepo % "test->test"
) // projectHandler tests need mock implementation of ProjectRepo
lazy val projectCore = project
.in(file("dsp-project/core"))
.settings(
scalacOptions ++= customScalacOptions,
name := "projectCore",
libraryDependencies ++= Dependencies.projectCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared)
lazy val projectRepo = project
.in(file("dsp-project/repo"))
.settings(
scalacOptions ++= customScalacOptions,
name := "projectRepo",
libraryDependencies ++= Dependencies.projectRepoLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared, projectCore)
// schema projects
lazy val schemaCore = project
.in(file("dsp-schema/core"))
.settings(
scalacOptions ++= customScalacOptions,
name := "schemaCore",
libraryDependencies ++= Dependencies.schemaCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared)
// Shared project
lazy val shared = project
.in(file("dsp-shared"))
.settings(
scalacOptions ++= customScalacOptions,
name := "shared",
libraryDependencies ++= Dependencies.sharedLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)