diff options
Diffstat (limited to 'project')
-rw-r--r-- | project/Build.scala | 37 | ||||
-rw-r--r-- | project/build.properties | 1 | ||||
-rw-r--r-- | project/plugins.sbt | 1 |
3 files changed, 39 insertions, 0 deletions
diff --git a/project/Build.scala b/project/Build.scala new file mode 100644 index 0000000..ec7f527 --- /dev/null +++ b/project/Build.scala @@ -0,0 +1,37 @@ +import sbt._ +import Keys._ +import Tests._ + +/** + * This is a simple sbt setup generating Slick code from the given + * database before compiling the projects code. + */ +object myBuild extends Build { + lazy val mainProject = Project( + id="main", + base=file("."), + settings = Project.defaultSettings ++ Seq( + scalaVersion := "2.10.3", + libraryDependencies ++= List( + "com.typesafe.slick" %% "slick" % "2.0.0-RC1", + "org.slf4j" % "slf4j-nop" % "1.6.4", + "com.h2database" % "h2" % "1.3.166" + ), + slick <<= slickCodeGenTask, // register manual sbt command + sourceGenerators in Compile <+= slickCodeGenTask // register automatic code generation on every compile, remove for only manual use + ) + ) + + // code generation task + lazy val slick = TaskKey[Seq[File]]("gen-tables") + lazy val slickCodeGenTask = (sourceManaged, dependencyClasspath in Compile, runner in Compile, streams) map { (dir, cp, r, s) => + val outputDir = (dir / "slick").getPath // place generated files in sbt's managed sources folder + val url = "jdbc:h2:mem:test;INIT=runscript from 'src/main/sql/create.sql'" // connection info for a pre-populated throw-away, in-memory db for this demo, which is freshly initialized on every run + val jdbcDriver = "org.h2.Driver" + val slickDriver = "scala.slick.driver.H2Driver" + val pkg = "demo" + toError(r.run("scala.slick.model.codegen.SourceCodeGenerator", cp.files, Array(slickDriver, jdbcDriver, url, outputDir, pkg), s.log)) + val fname = outputDir + "/demo/Tables.scala" + Seq(file(fname)) + } +}
\ No newline at end of file diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..0974fce --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.13.0 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..0b28604 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0")
|