Reputation: 1104
I have multiple projects in one directory, which are aggregated in sbt. I would like to write a task for sbt in build.sbt, which would make some commands in each project.
lazy val P1 = (project in file("P1")
lazy val P2 = (project in file("P2")
lazy val cleanEverywhere = taskKey[Unit]("Clean everywhere")
How am I supposed to write this cleanEverywhere task to clean each project?
Upvotes: 2
Views: 1877
Reputation: 48410
Try
val cleanAll = taskKey[Unit]("Clean all projects")
cleanAll := clean.all(ScopeFilter(inAnyProject)).value
where all
Evaluates the task in all scopes selected by the filter
and inAnyProject
selects all scopes along project axis.
Upvotes: 3
Reputation: 2527
Another way is to restructure your build.sbt
as following
lazy val root = (project in file(".")).aggregate(p1, p2)
lazy val p1 = project.in(file("p1"))
lazy val p2 = project.in(file("p2"))
this way, whenever you run sbt clean
, sbt test
, sbt compile
commands, every command will get executed against all the aggregated projects and you don't need to create cleanAll
task
And if you want project specific command, you can run it like sbt p1/compile
Upvotes: 3