光滑代码生成始终查找Tables.scala文件。为什么?

时间:2016-05-23 12:18:55

标签: scala sbt slick

我刚刚开始使用光滑,我需要从现有数据库生成模式。

我环顾了一下光头代码生成器,并在线查看了一些示例(所有内容看起来都一样,并生成相同的错误BTW)。

所以为了引用我的代码,这里是我引用的示例:

https://gist.github.com/matanster/512fb33d67e7ddd7eb46

它看起来像这样:

slickGenerate := {
  import java.io.File
  val dbName = "mydb"
  val userName = "mycomp"
  val password = "1234"
  val url = s"jdbc:mysql://localhost:3306/$dbName" // adapt as necessary to your system
  val jdbcDriver = "com.mysql.jdbc.Driver" // replace if not MySQL
  val slickDriver = "slick.driver.MySQLDriver" // replace if not MySQL
  val resultRelativeDir = "model" // directory to create output scala slick definitions at
  val targetPackageName = "com.pany.proj.model" // package name to give it
  val resultFilePath = s"$resultRelativeDir/$targetPackageName/Tables.scala" // override the name if you like
  val backupFilePath = s"$resultRelativeDir/$targetPackageName/Tables.scala.auto-backup" // override the name if you like
  val format = scala.Console.BLUE + scala.Console.BOLD
  println(format + s"Backing up existing slick mappings source to: file://${baseDirectory.value}/$backupFilePath")
  println(format + s"About to auto-generate slick mappings source from database schema at $url...")
  sbt.IO.copyFile(new File(resultFilePath), new File(backupFilePath))
  (runner in Compile).value.run("slick.codegen.SourceCodeGenerator", (dependencyClasspath in Compile).value.files, Array(slickDriver, jdbcDriver, url, resultRelativeDir, targetPackageName, userName, password), streams.value.log)
  println(format + s"Result: file://${baseDirectory.value}/$resultFilePath" + scala.Console.RESET)
  val diff = (s"diff -u $resultFilePath $backupFilePath" #| "colordiff").!!
  println(scala.Console.BLUE + s"Changes compared to previous output file, follow, if any.\n\n $diff")
  Seq(file(resultFilePath))
}

运行此代码时,我总是会收到以下错误:

Backing up existing slick mappings source to: file:///Users/me/Documents/views/proj/model/com.pany.proj.model/Tables.scala.auto-backup
About to auto-generate slick mappings source from database schema at jdbc:mysql://localhost:3306/pany...
java.lang.IllegalArgumentException: requirement failed: Source file '/Users/me/Documents/views/proj/model/com.pany.proj.model/Tables.scala' does not exist.
at scala.Predef$.require(Predef.scala:233)
at sbt.IO$.copyFile(IO.scala:636)
at $802a1e7ec0732f92084d$$anonfun$$sbtdef$1.apply(/Users/me/Documents/views/proj/build.sbt:60)
at $802a1e7ec0732f92084d$$anonfun$$sbtdef$1.apply(/Users/me/Documents/views/proj/build.sbt:45)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (*:slickGenerate) java.lang.IllegalArgumentException: requirement failed: Source file '/Users/me/Documents/views/proj/model/com.pany.proj.model/Tables.scala' does not exist.
[error] Total time: 0 s, completed May 23, 2016 3:04:59 PM

这真是令人沮丧,因为我的印象是代码生成器应该生成代码?!我做错了什么。

我也无法找出dirpackage name的东西。它看起来很有线,与它试图完成的事情无关。

0 个答案:

没有答案