简体   繁体   中英

Scala error: type mismatch

I have the following piece of code in an sbt.build file of a project I'm trying to run:

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:

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.

Note: I am using Scala version 2.11.4 and sbt version 1.0.2.

SBT's tasks and settings are a special kind of breed, you cannot use them literally in your code. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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