This repository has been archived by the owner on Jul 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.sbt
49 lines (40 loc) · 1.92 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
/**
* This is a slightly more advanced sbt setup using two projects.
* The first one, "codegen" a customized version of Slick's
* code-generator. The second one "main" depends on "codegen", which means
* it is compiled after "codegen". "main" uses the customized
* code-generator from project "codegen" as a sourceGenerator, which is run
* to generate Slick code, before the code in project "main" is compiled.
*/
/** main project containing main source code depending on slick and codegen project */
lazy val root = (project in file("."))
.settings(sharedSettings)
.settings(slick := slickCodeGenTask.value) // register manual sbt command)
.settings(sourceGenerators in Compile += slickCodeGenTask.taskValue) // register automatic code generation on every compile, remove for only manual use)
.dependsOn(codegen)
/** codegen project containing the customized code generator */
lazy val codegen = project
.settings(sharedSettings)
.settings(libraryDependencies += "com.typesafe.slick" %% "slick-codegen" % "3.1.1")
// shared sbt config between main project and codegen project
lazy val sharedSettings = Seq(
scalaVersion := "2.11.8",
scalacOptions := Seq("-feature", "-unchecked", "-deprecation"),
libraryDependencies ++= List(
"com.typesafe.slick" %% "slick" % "3.1.1",
"org.slf4j" % "slf4j-nop" % "1.7.10",
"com.h2database" % "h2" % "1.4.187"
)
)
// code generation task that calls the customized code generator
lazy val slick = taskKey[Seq[File]]("gen-tables")
lazy val slickCodeGenTask = Def.task {
val dir = sourceManaged.value
val cp = (dependencyClasspath in Compile).value
val r = (runner in Compile).value
val s = streams.value
val outputDir = (dir / "slick").getPath // place generated files in sbt's managed sources folder
toError(r.run("demo.CustomizedCodeGenerator", cp.files, Array(outputDir), s.log))
val fname = outputDir + "/demo/Tables.scala"
Seq(file(fname))
}