forked from alvinj/ScalaCookbook2Examples
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sbt
453 lines (404 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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
import sbt.Compile
import sbt.Keys.{ libraryDependencies, scalacOptions }
ThisBuild / organization := "com.alvinalexander"
name := "ScalaCookbook2Examples"
ThisBuild / version := "1.0.0"
ThisBuild / scalaVersion := "3.2.0"
lazy val akkaVersion = "2.6.4"
lazy val scalaVer = "2.13.9"
lazy val scalatestplusPlayVer = "5.0.0"
lazy val playJsonVer = "2.9.1"
lazy val sttpVer = "3.3.4"
lazy val ScalaCookbook2Examples = (project in file("."))
.aggregate(
`chapter1-jpackage`,
`chapter1-6`,
`chapter2`,
`chapter3`,
`chapter4`,
`chapter5`,
`chapter6`,
`chapter7`,
`chapter8`,
`chapter9`,
`chapter10`,
`chapter16`,
`chapter17-4`,
`chapter17-10`,
`chapter17-11`,
`chapter17-12`,
`chapter18-akka`,
`chapter18-future`,
`chapter19`,
`chapter19-1`,
`chapter19-2`,
`chapter19-3`,
`chapter19-4`,
`chapter19-5`,
`chapter19-6`,
`chapter19-7`,
`chapter19-ScalaSlowSocketServer`,
`chapter21`,
`chapter21-1`, // 表示第19章的第1小节的源代码
`chapter21-2`,
`chapter21-3`,
`chapter21-4-1`, // 表示第21章的第4小节的第1个源代码
`chapter21-4-2`,
`chapter21-5`,
`chapter22`,
`chapter23`,
`SimpleTest`
)
.enablePlugins(ScalafmtPlugin)
lazy val common =
scalacOptions ++= Seq(
"-deprecation", // emit warning and location for usages of deprecated APIs
"-explain", // explain errors in more detail
"-explain-types", // explain type errors in more detail
"-feature", // emit warning and location for usages of features that should be imported explicitly
"-indent", // allow significant indentation.
"-new-syntax", // require `then` and `do` in control expressions.
"-print-lines", // show source code line numbers.
"-unchecked", // enable additional warnings where generated code depends on assumptions
"-Ykind-projector", // allow `*` as wildcard to be compatible with kind projector
"-Xfatal-warnings", // fail the compilation if there are any warnings
"-Xmigration" // warn about constructs whose behavior may have changed since version
)
lazy val `chapter1-6` = (project in file("01_CommandLineTasks/06-RunJarFileWSbtAssembly"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
.settings(
name := "RunJarFile",
description := "Show how to use assembly and run jar files",
version := "0.1.0",
// set the main class for 'sbt run'
Compile / mainClass := Some("hello"),
run / mainClass := Some("hello"),
// set the main class for packaging the main jar
Compile / mainClass := Some("hello"),
packageBin / mainClass := Some("hello")
)
lazy val `chapter1-jpackage` = (project in file("01_CommandLineTasks/jpackage"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
.settings(
name := "MySwingApp",
description := "Lets me use the Scala 3 nightly build",
version := "0.1.0",
// scalaVersion := dottyLatestNightlyBuild.get,
run / fork := true
)
lazy val `chapter2` = (project in file("02_Strings"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
lazy val `chapter3` = (project in file("03_NumbersAndDates"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
lazy val `chapter4` = (project in file("04_ControlStructures"))
.enablePlugins(ScalafmtPlugin)
.settings(
common
)
.dependsOn(`SimpleTest`)
lazy val `chapter5` = (project in file("05_Classes"))
.enablePlugins(ScalafmtPlugin)
.settings(
common
)
.dependsOn(`SimpleTest`)
lazy val `chapter6` = (project in file("06_TraitsAndEnums"))
.enablePlugins(ScalafmtPlugin)
.settings(
common
)
.dependsOn(`SimpleTest`)
lazy val `chapter7` = (project in file("07_Objects"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
lazy val `chapter8` = (project in file("08_Methods"))
.enablePlugins(ScalafmtPlugin)
.settings(
common
)
.dependsOn(`SimpleTest`)
lazy val `chapter9` = (project in file("09_Packaging"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
lazy val `chapter10` = (project in file("10_FP"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
lazy val `chapter16` = (project in file("./16_Files_Processes"))
.enablePlugins(ScalafmtPlugin)
.settings(
common
)
.dependsOn(`SimpleTest`)
lazy val `chapter17-4` = (project in file("17_sbt/04_compiling_running"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "CompilingRunningPackaging",
scalacOptions ++= Seq(
"-deprecation",
"-explain",
"-explain-types",
"-new-syntax",
"-unchecked",
"-Xfatal-warnings",
"-Xmigration"
)
)
lazy val `chapter17-10` = (project in file("17_sbt/10_MainMethods"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "MyProject",
// set the main class for the 'sbt run' task
Compile / run / mainClass := Some("com.alvinalexander.Main1"),
// set the main class for the 'sbt package' task
Compile / packageBin / mainClass := Some("com.alvinalexander.Main2")
// ------------------------------- //
// a few other settings below here //
// ------------------------------- //
// set the main class for packaging the main jar
// mainClass in (Compile, packageBin) := Some("foo.bar.Goodbye")
// remove the 'run' setting to make the definition less narrow
// Compile / mainClass := Some("foo.bar.Baz")
)
lazy val `chapter17-11` = (project in file("17_sbt/11_Assembly"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "MyProject",
version := "0.1.0",
assembly / mainClass := Some("com.alvinalexander.myproject.Foo"),
assembly / assemblyJarName := "MyApp.jar",
assembly / test := {}
)
lazy val `chapter17-12` = (project in file("17_sbt/12_Publishing"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "StringUtils",
// for the 'publish' task; tells sbt to write its output to the
// "out" subdirectory
publishTo := Some(Resolver.file("file", new File("./out")))
)
lazy val `chapter18-akka` = (project in file("18_Concurrency_Futures/Akka_Examples"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "AkkaExamples",
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
"ch.qos.logback" % "logback-classic" % "1.2.3",
"com.typesafe.akka" %% "akka-actor-testkit-typed" % akkaVersion % Test,
"org.scalatest" %% "scalatest" % "3.1.0" % Test
),
scalaVersion := scalaVer // 没有指定的默认是3.2.0
)
.dependsOn(`SimpleTest`)
lazy val `chapter18-future` = (project in file("18_Concurrency_Futures/Future_Examples"))
.enablePlugins(ScalafmtPlugin)
.settings(common, name := "Concurrency_Futures")
.dependsOn(`SimpleTest`)
lazy val `chapter19` = (project in file("19_Web_Services"))
.enablePlugins(ScalafmtPlugin)
// Adds additional packages into Twirl
//TwirlKeys.templateImports += "com.alvinalexander.controllers._"
// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "com.alvinalexander.binders._"
lazy val `chapter19-1` = (project in file("19_Web_Services/01_Creating_Play_Project/hello-world"))
.enablePlugins(ScalafmtPlugin, PlayScala)
.settings(
scalaVersion := scalaVer,
name := """hello-world""",
libraryDependencies += guice,
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % scalatestplusPlayVer % Test
)
lazy val `chapter19-2` = (project in file("19_Web_Services/02_Creating_New_Play_Endpoint/hello-world"))
.enablePlugins(ScalafmtPlugin, PlayScala)
.settings(
name := """hello-world""",
scalaVersion := scalaVer,
libraryDependencies += guice,
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % scalatestplusPlayVer % Test
)
lazy val `chapter19-3` = (project in file("19_Web_Services/03_Returning_JSON_from_GET/hello-world"))
.enablePlugins(ScalafmtPlugin, PlayScala)
.settings(
name := """hello-world""",
scalaVersion := scalaVer,
libraryDependencies += guice,
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % scalatestplusPlayVer % Test
)
lazy val `chapter19-4` = (project in file("19_Web_Services/04_Serializing_Object_to_JSON"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "PlayJsonWithoutPlay",
scalaVersion := scalaVer,
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-json" % playJsonVer,
"com.softwaremill.sttp.client3" %% "core" % sttpVer
// "com.softwaremill.sttp.client3" %% "core" % sttpVer
),
// see https://tpolecat.github.io/2017/04/25/scalac-flags.html for scalacOptions descriptions
scalacOptions ++= Seq(
"-deprecation", // emit warning and location for usages of deprecated APIs
"-unchecked", // enable additional warnings where generated code depends on assumptions
"-explaintypes", // explain type errors in more detail
"-Ywarn-dead-code", // warn when dead code is identified
"-Xfatal-warnings" // fail the compilation if there are any warnings
)
)
lazy val `chapter19-5` = (project in file("19_Web_Services/05_Deserializing_JSON_to_Object"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "PlayJsonWithoutPlay",
scalaVersion := scalaVer,
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-json" % playJsonVer
),
// see https://tpolecat.github.io/2017/04/25/scalac-flags.html for scalacOptions descriptions
scalacOptions ++= Seq(
"-deprecation", // emit warning and location for usages of deprecated APIs
"-unchecked", // enable additional warnings where generated code depends on assumptions
"-explaintypes", // explain type errors in more detail
"-Ywarn-dead-code", // warn when dead code is identified
"-Xfatal-warnings" // fail the compilation if there are any warnings
)
)
lazy val `chapter19-6` = (project in file("19_Web_Services/06_Using_PlayJson_Without_Play"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "PlayJsonWithoutPlay",
scalaVersion := scalaVer,
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-json" % playJsonVer,
"com.softwaremill.sttp.client3" %% "core" % sttpVer
// "com.softwaremill.sttp.client3" %% "core" % sttpVer
),
// see https://tpolecat.github.io/2017/04/25/scalac-flags.html for scalacOptions descriptions
scalacOptions ++= Seq(
"-deprecation", // emit warning and location for usages of deprecated APIs
"-unchecked", // enable additional warnings where generated code depends on assumptions
"-explaintypes", // explain type errors in more detail
"-Ywarn-dead-code", // warn when dead code is identified
"-Xfatal-warnings" // fail the compilation if there are any warnings
)
)
lazy val `chapter19-7` = (project in file("19_Web_Services/07_Using_sttp_HTTP_Client"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "Sttp",
scalaVersion := "3.0.0",
libraryDependencies ++= Seq(
"com.softwaremill.sttp.client3" %% "core" % sttpVer
)
)
lazy val `chapter19-ScalaSlowSocketServer` = (project in file("19_Web_Services/ScalaSlowSocketServer"))
.enablePlugins(ScalafmtPlugin)
.settings(
name := "ScalaSlowSocketServer",
fork := true,
scalacOptions ++= Seq(
"-deprecation",
"-explain",
"-explain-types",
"-new-syntax",
"-unchecked",
"-Xfatal-warnings",
"-Xmigration"
)
)
lazy val `chapter21` = (project in file("21_Scala.js_GraalVM_jpackage"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
lazy val `chapter21-1` = (project in file("21_Scala.js_GraalVM_jpackage/01_ScalaJs_GettingStarted"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
.settings(
name := "ScalaJs Hello World",
scalaJSUseMainModuleInitializer := true,
libraryDependencies +=
("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13)
)
.enablePlugins(ScalaJSPlugin)
lazy val `chapter21-2` = (project in file("21_Scala.js_GraalVM_jpackage/02_ScalaJs_Events"))
.enablePlugins(ScalafmtPlugin, ScalaJSPlugin, JSDependenciesPlugin)
.dependsOn(`SimpleTest`)
.settings(
name := "ScalaJs2",
scalaJSUseMainModuleInitializer := true,
Compile / mainClass := Some("hello.hello2"),
libraryDependencies ++= Seq(
("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13),
("org.querki" %%% "jquery-facade" % "2.0").cross(CrossVersion.for3Use2_13)
),
jsDependencies += "org.webjars" % "jquery" % "2.2.1" / "jquery.js" minified "jquery.min.js"
)
lazy val `chapter21-3` = (project in file("21_Scala.js_GraalVM_jpackage/03_ScalaJs_SPA"))
.enablePlugins(ScalafmtPlugin, ScalaJSPlugin, JSDependenciesPlugin)
.dependsOn(`SimpleTest`)
.settings(
name := "ScalaJs3",
scalaJSUseMainModuleInitializer := true,
Compile / mainClass := Some("hello.Hello3"),
libraryDependencies ++= Seq(
("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13),
("org.querki" %%% "jquery-facade" % "2.0").cross(CrossVersion.for3Use2_13),
("com.lihaoyi" %%% "scalatags" % "0.9.4").cross(CrossVersion.for3Use2_13)
),
jsDependencies += "org.webjars" % "jquery" % "2.2.1" / "jquery.js" minified "jquery.min.js"
)
lazy val `chapter21-4-1` = (project in file("21_Scala.js_GraalVM_jpackage/04_GraalVM/01_Sbtmkdirs"))
.enablePlugins(ScalafmtPlugin, NativeImagePlugin)
.dependsOn(`SimpleTest`)
.settings(
name := "Sbtmkdirs",
Compile / mainClass := Some("sbtmkdirs.Sbtmkdirs"),
scalacOptions ++= Seq(
"-deprecation",
"-explain",
"-explain-types",
"-new-syntax",
"-unchecked",
"-Xfatal-warnings",
"-Xmigration"
)
)
lazy val `chapter21-4-2` = (project in file("21_Scala.js_GraalVM_jpackage/04_GraalVM/02_Bonus_HttpClient"))
.enablePlugins(ScalafmtPlugin, NativeImagePlugin)
.dependsOn(`SimpleTest`)
.settings(
name := "http_client",
scalacOptions ++= Seq(
"-deprecation",
"-explain",
"-explain-types",
"-new-syntax",
"-unchecked",
"-Xfatal-warnings",
"-Xmigration"
),
Compile / mainClass := Some("foo.HttpClient"),
nativeImageOptions ++=
Seq(
"-H:EnableURLProtocols=http",
"-H:EnableURLProtocols=https",
"--enable-url-protocols=http,https",
"--enable-https",
"--enable-http"
)
)
lazy val `chapter21-5` = (project in file("21_Scala.js_GraalVM_jpackage/05_jpackage"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
.settings(
name := "MySwingApp",
Compile / run / fork := true
)
lazy val `chapter22` = (project in file("22_Java_Integration"))
.enablePlugins(ScalafmtPlugin)
.dependsOn(`SimpleTest`)
lazy val `chapter23` = (project in file("23_Types"))
.dependsOn(`SimpleTest`)
.enablePlugins(ScalafmtPlugin)
lazy val `SimpleTest` = (project in file("SimpleTest"))
.enablePlugins(ScalafmtPlugin)
.settings(common)