mushroom mushroom - 8 months ago 34
Scala Question

How can I use a library dependency in the definition of an sbt task?

I am defining an sbt task that needs to call code in a library. Here is a build.sbt file with what I've tried so far:

libraryDependencies ++= Seq("" %% "some-lib" % "1.0.0")

val doSomething = taskKey[Unit]("does something")

doSomething := {

The imports do not work. How do I define a task that depends on code in an external library?


To build the .sbt file itself in the root directory, SBT uses information in the project directory. So put a build.sbt in the project directory and set the libraryDependencies key there:

libraryDependencies ++= Seq("" %% "some-lib" % "1.0.0")

So, to clarify, you now have two build.sbt files:

  1. ./build.sbt
  2. ./project/build.sbt