2

I want to use third party library in a taskKey in the .Scala/.sbt project files.

My problem is when I try to import the file I get a compilation error.

My goal is simple I want to add a task key that execute some logic using sbt cli, I have tried an example using sbt command line application, but it doesn't meet my need because I need to package the application to test the code.

So how could I import dependencies into sbt cli during the load phase?

Example:

val customTaskKey = TaskKey[Unit]("customTaskKey", "Runs customTaskKey")
lazy val myProjectSettings: Seq[Setting[_]] = Seq(
  customTaskKey :={

    val instance : ThirdPartLibraryClass()
    //             ^
    //            Symbol not found : compilation error
  }
)
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Ben Rhouma Zied
  • 2,473
  • 3
  • 19
  • 29

1 Answers1

3

You can add the dependency the normal way, but in the my-project/project/plugin.sbt file instead of my-project/build.sbt :

libraryDependencies ++= Seq(
  "thirdparty" % "library" % "1.0"
)

If your project is foo, foo/project is another SBT project, which builds the SBT build for the foo project. So configuration done in foo/project folder applies to the build for foo, rather than to foo itself.

Cyäegha
  • 4,191
  • 2
  • 20
  • 36