Is it possible to override or modify built-in SBT tasks (like compile) to depend on custom tasks in my own Build.scala? Overriding e.g. "compile" directly is not possible since it has been defined with lazy val and thus referring to super.compile emits a compiler error "super may be not be used on lazy value".
If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.
Creating a dependency between two tasks To do this, hover over the task that you want to be completed first. You will see a grey dot to the right of the task. Click and drag this to the task you want to create the dependency with. You will see an arrow created, linking the two tasks.
The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.
Since this question appears when Googling how to add a dependency in SBT, and the current answers are deprecated as of 0.13.x and removed in 1.0, here's the updated answer, assuming that printAction
is the task that compile
should depend on:
(Compile / compile) := ((Compile / compile) dependsOn printAction).value
Update: See arussell84's answer for a modern way to do this
You should be able to do it like this:
in a .sbt file:
compile <<= (compile in Compile) dependsOn jruby
Where jruby is a task key that you've defined in a project/something.scala file:
val jruby = TaskKey[Unit]("jruby", "run a jruby file")
Also, this isn't part of your question but you can just call regular Scala code:
compile <<= (compile in Compile) map { result => println("in compile, something") result }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With