SBT:无法定义任务

时间:2014-03-03 11:56:32

标签: scala sbt

这是我的任务。除了swager jar之外,它应该从战争的lib中删除所有内容。

packageCleanWar :=  {
  val war: File = (packageWar in Compile).value
  val tmpDir = target.value / "tmp"
  val warPath = war.getAbsolutePath
  val nf = (s: String) => s match {
    case s if s.startsWith("WEB-INF/lib/swagger") => true
    case s if s.startsWith("WEB-INF/lib/") => false
    case _ => true
  }
  IO.unzip(war, tmpDir, NameFilter.fnToNameFilter(nf))
  IO.delete(war)
  val newWar = new File(warPath)
  IO.zip(Path.allSubpaths(tmpDir), newWar)
  newWar
}

尝试加载时,我会收到以下内容

C:\work\project\server\build.sbt:55: error: not found: value packageCleanWar
packageCleanWar :=  {
^
[error] Type error in expression

尽管我用与here相同的风格来定义它。我做错了什么?

1 个答案:

答案 0 :(得分:2)

您需要声明任务并定义它:

lazy val packageCleanWar = taskKey[File]("packageCleanWar description")

packageCleanWar :=  {
  val war: File = (packageWar in Compile).value
  val tmpDir = target.value / "tmp"
  val warPath = war.getAbsolutePath
  val nf = (s: String) => s match {
    case s if s.startsWith("WEB-INF/lib/swagger") => true
    case s if s.startsWith("WEB-INF/lib/") => false
    case _ => true
  }
  IO.unzip(war, tmpDir, NameFilter.fnToNameFilter(nf))
  IO.delete(war)
  val newWar = new File(warPath)
  IO.zip(Path.allSubpaths(tmpDir), newWar)
  newWar
}

这是Tasks