首页 > 解决方案 > sbt 0.13.x 迁移到带有 shell 任务的 1.1.4

问题描述

我的任务是从 git 中为我的 Play Framework 应用程序获取前端:

lazy val frontend = taskKey[Unit]("Downloads frontend")
frontend := {
  val s: TaskStreams = streams.value
  val shell: Seq[String] = if (sys.props("os.name").contains("Windows")) Seq("cmd", "/c") else Seq("bash", "-c")
  val downloadRepo: Seq[String] = shell :+ "git clone git@bitbucket.org:user/frontend.git"
  val rmJs: Seq[String] = shell :+    "rm -rf frontend/dist/js && rm -rf public/design && mkdir public/design"
  val copy: Seq[String] = shell :+    "mv frontend/dist/* public/design/"
  val rmRepo: Seq[String] = shell :+    "rm -rf frontend"
  s.log.info("Downloading frontend...")
  if((downloadRepo #&& rmJs #&& copy #&& rmRepo !) == 0) {
    s.log.success("frontend downloaded successful!")
  } else {
    throw new IllegalStateException("frontend failed!")
  }
}

它适用于 sbt 0.13.x,但我想迁移到最新版本,它给了我一个错误:

error: value #&& is not a member of Seq[String]
  if((downloadRepo #&& rmJs #&& copy #&& rmRepo !) == 0) {

我检查了新文档但没有找到答案,我该如何迁移它?

标签: sbtmigration

解决方案


我猜你的意思是#&&操作员来自sys.process

#&&如果前一个命令以退出值 0 结束,则有条件地执行第二个命令。它反映了 shell 的&&.

sbt 0.13 有一个与 1.0 相似的 API,sys.process并在 1.0 中sys.process替换了它。因此,修复只是将其导入以将相关暗示添加到范围:

import scala.sys.process._

推荐阅读