简体   繁体   English

Scala错误:类型不匹配

[英]Scala error: type mismatch

I have the following piece of code in an sbt.build file of a project I'm trying to run: 我要运行的项目的sbt.build文件中包含以下代码:

lazy val buildAssistantJs = taskKey[Unit]("Build assistant JavaScript frontend")

buildAssistantJs := {
  println("Building assistant JavaScript frontend...")
 "npm install" #&& "npm update" #&& "npm run assistant-build" !
}

stage := stage dependsOn buildAssistantJs

which gives me the below error when I execute sbt run: 当我执行sbt run时,出现以下错误:

error: type mismatch;
found   : sbt.Def.Initialize[sbt.Task[sbt.File]]
    (which expands to)  sbt.Def.Initialize[sbt.Task[java.io.File]]
required: sbt.File
    (which expands to)  java.io.File
stage := stage dependsOn buildAssistantJs
               ^
[error] Type error in expression

Does anyone have any idea why this is and how to resolve the error? 有谁知道这是为什么,以及如何解决该错误? Please note I am trying to run it on Windows, in case this makes any difference. 请注意,我试图在Windows上运行它,以防万一。

Note: I am using Scala version 2.11.4 and sbt version 1.0.2. 注意:我使用的是Scala 2.11.4版和sbt 1.0.2版。

SBT's tasks and settings are a special kind of breed, you cannot use them literally in your code. SBT的taskssettings是一种特殊的类型,您不能在代码中直接使用它们。 One can use them only when defining other tasks (or settings) which introduces dependencies amongst them. 只有在定义其他任务(或设置)时才可以使用它们,这些任务(或设置)引入了它们之间的依赖性。

If you want to use a tasks value, you need to say so: 如果要使用任务值,则需要这样说:

 stage := (stage dependsOn buildAssistantJs).value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM