在sbt中引用src中的文件

时间:2018-04-25 01:04:49

标签: scala playframework sbt slick slick-3.0

我正在尝试修改光滑的codegen以使用我自己的SourceCodeGenerator。所以我创建了自己的类SourceCodeGenerator并将其放在app/utils下,其中app是我的源目录。我做了一个sbt任务并在util.MySourceCodeGenerator中引用了这个类(build.sbt),但我得到了可怕的

[error] (run-main-7) java.lang.ClassNotFoundException: utils.MySourceCodeGenerator
[error] java.lang.ClassNotFoundException: utils.MySourceCodeGenerator
[error]     at java.lang.ClassLoader.findClass(ClassLoader.java:530)
[error]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error]     at sbt.internal.inc.classpath.ClasspathFilter.loadClass(ClassLoaders.scala:70)
[error]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error]     at java.lang.Class.forName0(Native Method)
[error]     at java.lang.Class.forName(Class.java:348)
[error]     at sbt.Run.getMainMethod(Run.scala:98)
[error]     at sbt.Run.run0(Run.scala:86)
[error]     at sbt.Run.execute$1(Run.scala:65)

运行自定义任务时:

sourceGenerators in Compile += slick.taskValue // Automatic code generation on build
lazy val slick = taskKey[Seq[File]]("Generate Tables.scala")

slick := {
  val dir = (scalaSource in Compile) value
  val outputDir = dir
  val jdbcDriver = "org.postgresql.Driver"
  val slickDriver = "slick.jdbc.PostgresProfile"
  val pkg = "models"

  val cp = (dependencyClasspath in Compile) value
  val s = streams value

  runner.value.run("utils.MySourceCodeGenerator",
    cp.files,
    Array(slickDriver, jdbcDriver, url, outputDir.getPath, pkg, user, password),
    s.log).failed foreach (sys error _.getMessage)

  val file = outputDir / pkg / "Tables.scala"

  Seq(file)
}

我是否需要更改项目结构?作为参考,我在玩!框架和我基本上遵循这个https://www.playframework.com/documentation/2.6.x/Anatomy

0 个答案:

没有答案