问题
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?
回答1:
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.
回答2:
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.
回答3:
I've figured it out:
lazy val taskSettings = Seq(
all <<= c dependsOn (b dependsOn a)
)
来源:https://stackoverflow.com/questions/16209690/how-to-alias-a-sequence-of-tasks