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 sinc
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
}
In the base_dir/project/
folder create a file build.sbt
and put libraryDependencies += ...
there.
That's the idiomatic SBT way to build your "build project", also known as "Meta Build".
Reply to self: http://code.google.com/p/simple-build-tool/wiki/ProjectDefinitionExamples#Insert_Task_Dependency tells the answer:
If you are using older 0.7.x SBT versions you can do this:
import sbt._
class SampleProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val printAction = task { print("Testing...") }
override def compileAction = super.compileAction dependsOn(printAction)
}
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