不能在sbt构建定义代码中使用导入

mat*_*ter 1 scala sbt

我尝试在sbt中导入JSON库,以便我的自定义sbt任务可以使用JSON api编写json文件.然而,似乎sbt无法导入这些库,而是它只能导入"标准"库,如scala.io.Source,java.io.File等...

两个注释掉下面的行都会失败sbt:

libraryDependencies += "com.typesafe.play" %% "play-json" % "2.3.7"

libraryDependencies += "io.argonaut" %% "argonaut" % "6.0.4"    

compile in Compile <<= (compile in Compile) map { c => 
  import scala.io.Source
  //import play.api.libs.json.Json
  //import argonaut._, Argonaut._
Run Code Online (Sandbox Code Playgroud)

可能是什么?我必须写一个插件来规避这个吗?

$ about
[info] This is sbt 0.13.6
[info] The current project is built against Scala 2.11.6
[info] Available Plugins: ...
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
Run Code Online (Sandbox Code Playgroud)

当然我可以直接插入我的json裸手但我不知道它会是什么......

谢谢!

Mic*_*jac 6

根据插件文档中的这个片段,您只需要包含依赖项plugins.sbt而不是构建定义(即,不需要插件).

// [within plugins.sbt]
// plain library (not an sbt plugin) for use in the build definition
libraryDependencies += "org.example" % "utilities" % "1.3"
Run Code Online (Sandbox Code Playgroud)

所以你应该能够将这些添加到plugins.sbt:

libraryDependencies += "com.typesafe.play" %% "play-json" % "2.3.7"

libraryDependencies += "io.argonaut" %% "argonaut" % "6.0.4"  
Run Code Online (Sandbox Code Playgroud)