3

我无法让我的新 SBT 任务“安装”依赖于OneJar任务。这是我的 Build.scala 文件:

import sbt._
import Keys._
import com.github.retronym.SbtOneJar._

object BuildBroBuild extends Build {
  val install = TaskKey[Unit]("install", "Installs the JAR and a launcher script into your homedir")

  private def installTask = task {
    println("Hello world!")
  }

  override lazy val settings = super.settings ++
    Seq(install <<= (oneJar in Global)(installTask dependsOn(_)))

  lazy val root = Project(id = "buildbro",
                          base = file("."),
                          settings = Project.defaultSettings)
}

这是我得到的错误:

[error] Reference to undefined setting: 
[error] 
[error]   */*:one-jar from {.}/*:install
[error]      Did you mean *:one-jar ?
[error]  

有人知道这是什么意思吗?我相信我必须以不同的方式确定 oneJar TaskKey 的范围。谢谢你的尽心帮助。

4

1 回答 1

1

我认为这样的事情应该有效:

object BuildBroBuild extends Build {
  val install = TaskKey[Unit]("install", "Installs the JAR and a launcher script into your homedir")

  private lazy val installTask = install <<= (oneJar, streams) map { case (a, s) => {
    // 'a' is the output from the onejar task (ie, the artifact)
    println("Hello world!")
  }

  override lazy val settings = super.settings ++
    Seq(installTask)

  lazy val root = Project(id = "buildbro",
                          base = file("."),
                          settings = Project.defaultSettings)
}

在这里,我们将 oneJar 任务的输出(以及streams允许记录等)作为我们新任务的输入。

于 2012-07-06T19:57:59.867 回答