-
Notifications
You must be signed in to change notification settings - Fork 36
/
build.sbt
486 lines (417 loc) · 17 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
import org.openqa.selenium.Capabilities
import org.openqa.selenium.firefox.{FirefoxDriverLogLevel, FirefoxOptions}
import org.scalajs.jsdependencies.sbtplugin.JSModuleID
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
import org.scalajs.jsenv.selenium.SeleniumJSEnv
name := "udash"
Global / excludeLintKeys ++= Set(ideOutputDirectory, ideSkipProject)
inThisBuild(Seq(
version := "0.9.0-SNAPSHOT",
organization := "io.udash",
resolvers += Resolver.defaultLocal,
))
val forIdeaImport = System.getProperty("idea.managed", "false").toBoolean && System.getProperty("idea.runid") == null
val CompileAndTest = "test->test;compile->compile"
// Settings for JS tests run in browser
val browserCapabilities: Capabilities = {
// requires gecko driver, see https://github.com/mozilla/geckodriver
new FirefoxOptions().setHeadless(true).setLogLevel(FirefoxDriverLogLevel.WARN)
}
// Deployment configuration
val deploymentConfiguration = Seq(
publishMavenStyle := true,
Test / publishArtifact := false,
pomIncludeRepository := { _ => false },
publishTo := sonatypePublishToBundle.value,
credentials in Global += Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
sys.env.getOrElse("SONATYPE_USERNAME", ""),
sys.env.getOrElse("SONATYPE_PASSWORD", "")
),
licenses := Seq(License.Apache2),
pomExtra := {
<url>https://github.com/UdashFramework/udash-core</url>
<scm>
<url>[email protected]:UdashFramework/udash-core.git</url>
<connection>scm:[email protected]:UdashFramework/udash-core.git</connection>
</scm>
<developers>
<developer>
<id>avsystem</id>
<name>AVSystem</name>
<url>http://www.avsystem.com/</url>
</developer>
</developers>
}
)
val commonSettings = Seq(
scalaVersion := Dependencies.versionOfScala,
crossScalaVersions := Seq(Dependencies.versionOfScala),
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-unchecked",
"-language:implicitConversions",
"-language:existentials",
"-language:dynamics",
"-language:postfixOps",
"-language:higherKinds",
"-language:experimental.macros",
"-Xfatal-warnings",
"-Xlint:_,-missing-interpolator,-unused",
"-Xsource:3",
"-Yrangepos",
"-Ybackend-parallelism", "8",
"-Ycache-plugin-class-loader:last-modified",
"-Ycache-macro-class-loader:last-modified",
"-Xnon-strict-patmat-analysis",
"-Xlint:-strict-unsealed-patmat",
),
moduleName := "udash-" + moduleName.value,
Compile / doc / sources := Seq.empty,
Compile / ideOutputDirectory := Some(target.value.getParentFile / "out/production"),
Test / ideOutputDirectory := Some(target.value.getParentFile / "out/test"),
libraryDependencies ++= Dependencies.compilerPlugins.value,
libraryDependencies ++= Dependencies.commonTestDeps.value,
) ++ deploymentConfiguration
val commonJsSettings = commonSettings ++ Seq(
Test / scalaJSStage := FastOptStage,
Test / scalaJSUseMainModuleInitializer := false,
Test / jsEnv := new JSDOMNodeJSEnv,
scalacOptions += {
val localDir = (ThisBuild / baseDirectory).value.toURI.toString
val githubDir = "https://raw.githubusercontent.com/UdashFramework/udash-core"
s"-P:scalajs:mapSourceURI:$localDir->$githubDir/v${version.value}/"
},
libraryDependencies ++= Dependencies.commonJsTestDeps.value,
)
val testInBrowser = Seq(
Test / parallelExecution := false,
Test / jsEnv := new SeleniumJSEnv(browserCapabilities),
)
val noPublishSettings = Seq(
publish / skip := true,
Compile / packageDoc / mappings := Seq.empty,
)
val aggregateProjectSettings = noPublishSettings ++ Seq(
ideSkipProject := true,
crossScalaVersions := Nil,
)
def sourceDirsSettings(baseMapper: File => File) = {
def mkSourceDirs(base: File, scalaBinary: String, conf: String): Seq[File] = Seq(
base / "src" / conf / "scala",
base / "src" / conf / s"scala-$scalaBinary",
base / "src" / conf / "java"
)
def mkResourceDirs(base: File, conf: String): Seq[File] = Seq(
base / "src" / conf / "resources"
)
Seq(
Compile / unmanagedSourceDirectories ++=
mkSourceDirs(baseMapper(baseDirectory.value), scalaBinaryVersion.value, "main"),
Compile / unmanagedResourceDirectories ++=
mkResourceDirs(baseMapper(baseDirectory.value), "main"),
Test / unmanagedSourceDirectories ++=
mkSourceDirs(baseMapper(baseDirectory.value), scalaBinaryVersion.value, "test"),
Test / unmanagedResourceDirectories ++=
mkResourceDirs(baseMapper(baseDirectory.value), "test"),
)
}
def jvmProject(proj: Project): Project =
proj.settings(
commonSettings,
sourceDirsSettings(_ / ".jvm"),
)
def jsProject(proj: Project): Project =
proj.in(proj.base / ".js")
.enablePlugins(ScalaJSPlugin, JSDependenciesPlugin)
.settings(commonJsSettings)
def jsProjectFor(jsProj: Project, jvmProj: Project): Project =
jsProj.in(jvmProj.base / ".js")
.enablePlugins(ScalaJSPlugin, JSDependenciesPlugin)
.configure(p => if (forIdeaImport) p.dependsOn(jvmProj) else p)
.settings(
commonJsSettings,
moduleName := (jvmProj / moduleName).value,
sourceDirsSettings(_.getParentFile),
// workaround for some cross-compilation problems in IntelliJ
libraryDependencies ++= (if (forIdeaImport) (jvmProj / libraryDependencies).value else Seq.empty)
)
def frontendExecutable(proj: Project)(
staticsRoot: String,
jsDeps: Def.Initialize[Seq[JSModuleID]],
cssRenderer: Option[(Project, String)] = None,
additionalAssetsDirectory: Def.Initialize[Task[Option[File]]] = Def.task(None),
) = {
proj
.enablePlugins(ScalaJSPlugin, JSDependenciesPlugin, SbtWeb)
.settings(commonJsSettings)
.settings(
noPublishSettings,
crossScalaVersions := Seq(Dependencies.versionOfScala),
jsDependencies ++= jsDeps.value,
Compile / scalaJSUseMainModuleInitializer := true,
//library CSS settings
Assets / LessKeys.cleancss := true,
Assets / LessKeys.compress := true,
Assets / LessKeys.strictMath := true,
Assets / LessKeys.verbose := true,
Assets / LessKeys.less / includeFilter := "assets.less",
Assets / LessKeys.less / resourceManaged := (Compile / target).value / staticsRoot / "assets" / "styles",
//fastOptJS invokes less, which would fail without additional assets (e.g. prism.css)
Assets / LessKeys.less := (Assets / LessKeys.less).dependsOn(Compile / copyAssets).value,
Compile / copyAssets := {
val udashStatics = target.value / staticsRoot
val assets = udashStatics / "assets"
additionalAssetsDirectory.value.foreach(IO.copyDirectory(_, assets))
IO.copyDirectory(sourceDirectory.value / "main" / "assets", assets)
IO.move(assets / "index.html", udashStatics / "index.html")
IO.delete(assets / "assets.less")
// copying font-awesome webfonts to a location required by font-awesome styles
// (appropriate CSS file is inlined by less within UdashStatics/WebContent/guide/assets/styles/assets.min.css)
IO.copyDirectory(
(Assets / WebKeys.webJarsDirectory).value / WebKeys.webModulesLib.value / "font-awesome/webfonts",
assets / "webfonts"
)
},
// a font-awesome WebJar is required on the classpath to execute the copyAssets task
Compile / copyAssets := (Compile / copyAssets).dependsOn(Assets / WebKeys.webJars).value,
// Compiles CSS files and put them in the target directory
compileCss := Def.taskDyn {
cssRenderer.map { case (rendererProject, rendererClass) =>
val dir = (Compile / target).value / staticsRoot / "styles"
val path = dir.absolutePath
dir.mkdirs()
(rendererProject / Compile / runMain).toTask(s" $rendererClass $path false")
}.getOrElse(Def.task(()))
}.value,
// Compiles JS files without full optimizations
compileStatics := (Compile / fastOptJS / target).value / "UdashStatics",
compileStatics := compileStatics.dependsOn(Compile / fastOptJS, Compile / compileCss).value,
// Compiles JS files with full optimizations
compileAndOptimizeStatics := (Compile / fullOptJS / target).value / "UdashStatics",
compileAndOptimizeStatics := compileAndOptimizeStatics.dependsOn(
Compile / fullOptJS, Compile / copyAssets, Compile / compileCss
).value,
// force fullOpt dependencies generation after fastOpt deps generation
Compile / packageMinifiedJSDependencies :=
(Compile / packageMinifiedJSDependencies).dependsOn(Compile / packageJSDependencies).value,
// Target files for Scala.js plugin
Compile / fastOptJS / artifactPath :=
(Compile / fastOptJS / target).value / staticsRoot / "scripts" / "frontend.js",
Compile / fullOptJS / artifactPath :=
(Compile / fullOptJS / target).value / staticsRoot / "scripts" / "frontend.js",
Compile / packageJSDependencies / artifactPath :=
(Compile / packageJSDependencies / target).value / staticsRoot / "scripts" / "frontend-deps.js",
Compile / packageMinifiedJSDependencies / artifactPath :=
(Compile / packageMinifiedJSDependencies / target).value / staticsRoot / "scripts" / "frontend-deps.js"
)
}
lazy val udash = project.in(file("."))
.aggregate(`udash-jvm`, `udash-js`, guide)
.settings(
aggregateProjectSettings,
ideSkipProject := false,
)
//for simplifying Travis build matrix and project dependencies
lazy val jvmLibraries = Seq[ProjectReference](macros, utils, core, rpc, rest, `rest-jetty`, i18n, auth, css)
lazy val `udash-jvm` = project.in(file(".jvm"))
.aggregate(jvmLibraries: _*)
.settings(aggregateProjectSettings)
lazy val jsLibraries = Seq[ProjectReference](
macros, `utils-js`, `core-js`, `rpc-js`, `rest-js`, `i18n-js`, `auth-js`, `css-js`, bootstrap4
)
lazy val `udash-js` = project.in(file(".js"))
.aggregate(jsLibraries: _*)
.settings(aggregateProjectSettings)
lazy val macros = project
.settings(
commonSettings,
libraryDependencies ++= Dependencies.macroDeps.value,
)
lazy val utils = jvmProject(project)
.dependsOn(macros)
.settings(
libraryDependencies ++= Dependencies.utilsJvmDeps.value,
)
lazy val `utils-js` = jsProjectFor(project, utils)
.dependsOn(macros)
.settings(
libraryDependencies ++= Dependencies.utilsSjsDeps.value,
)
lazy val core = jvmProject(project)
.dependsOn(utils % CompileAndTest)
.settings(
libraryDependencies ++= Dependencies.coreJvmDeps.value,
)
lazy val `core-js` = jsProjectFor(project, core)
.dependsOn(`utils-js` % CompileAndTest)
.settings(
testInBrowser,
libraryDependencies ++= Dependencies.coreSjsDeps.value,
)
lazy val rpc = jvmProject(project)
.dependsOn(utils % CompileAndTest)
.settings(
libraryDependencies ++= Dependencies.rpcJvmDeps.value,
)
lazy val `rpc-js` = jsProjectFor(project, rpc)
.dependsOn(`utils-js` % CompileAndTest)
.settings(
libraryDependencies ++= Dependencies.rpcSjsDeps.value,
jsDependencies ++= Dependencies.rpcJsDeps.value,
)
lazy val rest = jvmProject(project)
.dependsOn(utils % CompileAndTest)
.settings(
libraryDependencies ++= Dependencies.restJvmDeps.value,
)
lazy val `rest-js` = jsProjectFor(project, rest)
.dependsOn(`utils-js` % CompileAndTest)
.settings(
libraryDependencies ++= Dependencies.restSjsDeps.value,
)
lazy val `rest-jetty` = jvmProject(project.in(file("rest/jetty")))
.dependsOn(rest % CompileAndTest)
.settings(
libraryDependencies ++= Dependencies.restJettyDeps.value,
)
lazy val i18n = jvmProject(project)
.dependsOn(core % CompileAndTest, rpc % CompileAndTest)
lazy val `i18n-js` = jsProjectFor(project, i18n)
.dependsOn(`core-js` % CompileAndTest, `rpc-js` % CompileAndTest)
lazy val auth = jvmProject(project)
.dependsOn(core % CompileAndTest, rpc)
lazy val `auth-js` = jsProjectFor(project, auth)
.dependsOn(`core-js` % CompileAndTest, `rpc-js`)
lazy val css = jvmProject(project)
.dependsOn(core % CompileAndTest)
.settings(
libraryDependencies ++= Dependencies.cssJvmDeps.value,
)
lazy val `css-js` = jsProjectFor(project, css)
.dependsOn(`core-js` % CompileAndTest)
.settings(
libraryDependencies ++= Dependencies.cssSjsDeps.value,
)
lazy val bootstrap4 = jsProject(project)
.dependsOn(`core-js` % CompileAndTest, `css-js`, `i18n-js` % Test)
.settings(
testInBrowser,
libraryDependencies ++= Dependencies.bootstrap4SjsDeps.value,
jsDependencies ++= Dependencies.bootstrap4JsDeps.value
)
lazy val benchmarks = jsProject(project)
.dependsOn(jsLibraries.map(p => p: ClasspathDep[ProjectReference]): _*)
.settings(
noPublishSettings,
crossPaths := false,
crossScalaVersions := Seq(Dependencies.versionOfScala),
libraryDependencies ++= Dependencies.benchmarksSjsDeps.value,
Compile / scalaJSUseMainModuleInitializer := true,
evictionErrorLevel := Level.Warn, //todo: remove after upickle 2.0.1+ is available
)
// Custom SBT tasks
val copyAssets = taskKey[Unit]("Copies all assets to the target directory.")
val compileCss = taskKey[Unit]("Compiles CSS files.")
val compileStatics = taskKey[File](
"Compiles JavaScript files and copies all assets to the target directory."
)
val compileAndOptimizeStatics = taskKey[File](
"Compiles and optimizes JavaScript files and copies all assets to the target directory."
)
lazy val guide = project.in(file("guide"))
.aggregate(`guide-shared`, `guide-shared-js`, `guide-backend`, `guide-commons`, `guide-homepage`,
`guide-guide`, `guide-packager`, `guide-selenium`)
.settings(
aggregateProjectSettings,
ideSkipProject := true,
)
lazy val `guide-shared` =
jvmProject(project.in(file("guide/shared")))
.dependsOn(jvmLibraries.map(p => p: ClasspathDep[ProjectReference]): _*)
.settings(
noPublishSettings,
crossScalaVersions := Seq(Dependencies.versionOfScala),
)
lazy val `guide-shared-js` =
jsProjectFor(project, `guide-shared`)
.dependsOn(jsLibraries.map(p => p: ClasspathDep[ProjectReference]): _*)
.settings(
noPublishSettings,
crossScalaVersions := Seq(Dependencies.versionOfScala),
)
lazy val `guide-backend` =
jvmProject(project.in(file("guide/backend")))
.dependsOn(`guide-shared`)
.settings(
noPublishSettings,
crossScalaVersions := Seq(Dependencies.versionOfScala),
libraryDependencies ++= Dependencies.backendDeps.value,
Compile / mainClass := Some("io.udash.web.Launcher"),
)
lazy val `guide-commons` =
jsProject(project.in(file("guide/commons")))
.enablePlugins(SbtWeb)
.dependsOn(`guide-shared-js`)
.settings(
noPublishSettings,
crossScalaVersions := Seq(Dependencies.versionOfScala),
libraryDependencies ++= Dependencies.guideFrontendDeps.value,
)
lazy val `guide-homepage` =
frontendExecutable(jsProject(project.in(file("guide/homepage"))).dependsOn(`guide-commons`))(
"UdashStatics/WebContent/homepage",
Dependencies.homepageJsDeps,
Some((`guide-backend`, "io.udash.web.styles.HomepageCssRenderer")),
Def.task(Some((`guide-commons` / sourceDirectory).value / "main" / "assets"))
)
lazy val `guide-guide` =
frontendExecutable(jsProject(project.in(file("guide/guide"))).dependsOn(`guide-commons`))(
"UdashStatics/WebContent/guide",
Dependencies.guideJsDeps,
Some((`guide-backend`, "io.udash.web.styles.GuideCssRenderer")),
Def.task(Some((`guide-commons` / sourceDirectory).value / "main" / "assets"))
)
lazy val `guide-packager` =
project.in(file("guide/packager"))
.dependsOn(`guide-backend`)
.enablePlugins(JavaServerAppPackaging)
.settings(
noPublishSettings,
commonSettings,
crossScalaVersions := Seq(Dependencies.versionOfScala),
normalizedName := "udash-guide",
maintainer := "[email protected]",
Compile / mainClass := (`guide-backend` / Compile / mainClass).value,
// add homepage statics to the package
Universal / mappings ++= {
import Path.relativeTo
val frontendStatics = (`guide-homepage` / Compile / compileAndOptimizeStatics).value
(frontendStatics.allPaths --- frontendStatics) pair relativeTo(frontendStatics.getParentFile)
},
// add guide statics to the package
Universal / mappings ++= {
import Path.relativeTo
val frontendStatics = (`guide-guide` / Compile / compileAndOptimizeStatics).value
(frontendStatics.allPaths --- frontendStatics) pair relativeTo(frontendStatics.getParentFile)
},
dockerExposedPorts += 8080, //should match ui.server.port
dockerEnvVars += "DISABLE_FILE_LOGGING" -> "true",
dockerBaseImage := "eclipse-temurin:17-jdk-jammy",
dockerUpdateLatest := true,
)
lazy val `guide-selenium` =
jvmProject(project.in(file("guide/selenium")))
.dependsOn(`guide-backend`)
.settings(
noPublishSettings,
crossScalaVersions := Seq(Dependencies.versionOfScala),
libraryDependencies ++= Dependencies.seleniumDeps,
Test / parallelExecution := false,
Test / compile := (Test / compile).dependsOn(
`guide-homepage` / Compile / compileStatics,
`guide-guide` / Compile / compileStatics,
).value
)