matanox
matanox

Reputation: 13686

Can't use imports inside sbt build definition code

I tried importing JSON libraries in sbt, so that my custom sbt task can write a json file using a JSON api. However it seems like sbt can't import those libraries, but rather it can only import "standard" libraries like scala.io.Source, java.io.File, etc...

Both commented out lines below would each fail 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._

What might it be? Must I write a plugin to circumvent this?

$ 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

Of course I can just string interpolate my json bare-handed but I wonder what might it be...

Thanks!

Upvotes: 1

Views: 225

Answers (1)

Michael Zajac
Michael Zajac

Reputation: 55569

According to this snippet from the plugin documentation, you just need to include the dependency in plugins.sbt instead of your build definition (ie., no plugin is required).

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

So you should be able to just add these to plugins.sbt:

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

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

Upvotes: 6

Related Questions