我正在处理 sbt 任务,我希望能够访问一些应用程序类和依赖项。
(具体来说,我想使用 scalaquery 生成数据库 DDL)
有什么方法可以将这些依赖项添加到任务中,或者我可能需要为此创建一个插件?
object ApplicationBuild extends Build {
val appName = "test"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"org.scalaquery" % "scalaquery_2.9.0-1" % "0.9.5")
val ddl = TaskKey[Unit]("ddl", "Generates the ddl in the evolutions folder")
val ddlTask = ddl <<= (baseDirectory, fullClasspath in Runtime) map { (bs, cp) =>
val f = bs / "conf/evolutions/default"
// Figures out the last sql number used
def nextFileNumber = { ... }
//writes to file
def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) { ...}
def createDdl = {
import org.scalaquery.session._
import org.scalaquery.ql._
import org.scalaquery.ql.TypeMapper._
import org.scalaquery.ql.extended.H2Driver.Implicit._
import org.scalaquery.ql.extended.{ ExtendedTable => Table }
import models._
printToFile(new java.io.File(nextFileNumber, f))(p => {
models.Table.ddl.createStatements.foreach(p.println)
});
}
createDdl
None
}
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
ddlTask)
}
我得到的错误是
[test] $ reload
[info] Loading global plugins from /home/asal/.sbt/plugins
[info] Loading project definition from /home/asal/myapps/test/project
[error] /home/asal/myapps/test/project/Build.scala:36: object scalaquery is not a member of package org
[error] import org.scalaquery.session._
[error] ^
[error] one error found
提前致谢
您必须添加 ScalaQuery 以及您的构建所依赖的所有其他内容作为构建依赖项。这意味着基本上,您必须将其添加为“作为 sbt 插件”。
这在使用插件 https://github.com/harrah/xsbt/wiki/Getting-Started-Using-Pluginssbt wiki 的部分。不过,这一切都归结为一件非常简单的事情 - 只需在下面添加一行定义您的依赖项project/plugins.sbt
像这样:
libraryDependencies += "org.scalaquery" % "scalaquery_2.9.0-1" % "0.9.5"
现在,在构建中使用应用程序类的问题是您无法真正将构建产品添加为构建依赖项。 - 因此,您可能必须创建一个单独的项目来构建 DDL 模块,并将其作为依赖项添加到该项目的构建中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)