21

I have custom tasks in my SBT (0.12.2) project. Let's call them a, b and c. So when I'm in the interactive mode of SBT I can just type a and the task associated with a is executed. I also can type ;a;b;c and the three tasks are executed in sequence; the same way something like ;clean;compile would do. What I also can do from the interactive shell is create an alias to run them all: alias all=;a;b;c. Now when I type all the tasks are executed in an obvious manner. What I'm trying to achieve is creating this alias inside of the SBT configuration for my project.

This section of SBT documentation deals with tasks, but all I could achieve was something like this:

lazy val a = TaskKey[Unit]("a", "does a")
lazy val b = TaskKey[Unit]("b", "does b")
lazy val c = TaskKey[Unit]("c", "does c")
lazy val all = TaskKey[Unit]("all", ";a;b;c")

lazy val taskSettings = Seq(
    all <<= Seq(a,b,c).dependOn
)

The problem I have with this approach is that the tasks are combined and thus their execution happens in parallel in contrast to sequential, which is what I'm trying to achieve. So how can I create an alias like alias all=;a;b;c inside of the SBT configuration file?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
agilesteel
  • 16,775
  • 6
  • 44
  • 55

3 Answers3

35

I've been looking for the same thing and found this request for an easy way of aliasing and the commit that provides one: addCommandAlias.

In my build.sbt I now have:

addCommandAlias("go", ";container:start;~copy-resources")

As you might guess, writing go in the console will now run the longer command sequence for me.

lime
  • 6,901
  • 4
  • 39
  • 50
  • 1
    Yeah, they are going to add a bunch of cool stuff in 0.13. You probably won't even need the full-build configuration anymore by the time it gets released. – agilesteel May 08 '13 at 09:11
  • Huh, I didn't even notice the version tag. It works for me in 0.12.1. :) – lime May 08 '13 at 09:53
11

another way to achieve this is to define an alias in your .sbtrc file which will be in the root of your project directory.

alias all=;a;b;c

you have an additional option of defining these .sbtrc file in your home directory in which case this alias will be available to all your projects.

rogue-one
  • 11,259
  • 7
  • 53
  • 75
9

I've figured it out:

lazy val taskSettings = Seq(
    all <<= c dependsOn (b dependsOn a)
)
agilesteel
  • 16,775
  • 6
  • 44
  • 55
  • I wonder why do all that "dependsOn"-thing given that the sequence is defined already ";a;b;c" or why defining ";a;b;c" if `c dependsOn (b dependsOn a)` is set – ses May 11 '16 at 23:17