sbt任务类路径 [英] sbt Task classpath

查看:116
本文介绍了sbt任务类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理sbt Task,我希望可以访问某些应用程序类和依赖项. (具体来说,我想使用scalaquery生成数据库DDL)

I'm working on a sbt Task and I would like to have access to some of the application classes and dependencies. (Specifically, I'd like to generate the Database DDL using scalaquery)

是否有任何方法可以将那些依赖项添加到任务中,或者也许我需要为此创建一个插件?

Is there any way to add those dependencies to the task or maybe I need to create a plugin for this?

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插件"添加.

You have to add ScalaQuery and everything else your build depends on as a build dependency. That means that basically, you have to add it "as an sbt plugin".

使用插件中对此进行了详细说明. sbt Wiki的部分.不过,这全都可以归结为一个非常简单的事情-只需在project/plugins.sbt下添加一行定义您的依赖项,如下所示:

This is described in some detail in the Using Plugins section of the sbt wiki. It all boils down to a very simple thing, though - just add a line defining your dependency under project/plugins.sbt like this:

libraryDependencies += "org.scalaquery" % "scalaquery_2.9.0-1" % "0.9.5"

现在,在构建中使用应用程序类的问题是您不能真正将构建产品添加为构建依赖项. -因此,您可能必须创建一个单独的项目来构建DDL模块,并将其作为依赖项添加到该项目的构建中.

Now, the problem with using application classes in the build is that you can't really add build products as build dependencies. - So, you would probably have to create a separate project that builds your DDL module, and add that as dependency to the build of this project.

这篇关于sbt任务类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆