SBT: how to exclude one sub-project from one aggregated task
Asked Answered
O

0

6

I have a bunch of sub-project that I define as follows (actually generated by a project/meta.sbt):

lazy val Top = (project in file("."))
  .aggregate(common, p1, p2, tests, scripts)
  .dependsOn(common, p1, p2, tests, scripts)
lazy val common = project
lazy val p1 = project.dependsOn(common % "compile->compile;test->test")
lazy val p2 = project.dependsOn(common % "compile->compile;test->test")
lazy val tests = project.dependsOn(common % "compile->compile;test->test")
lazy val scripts = project

AFAICT (so maybe that's wrong), both the aggregate and the dependsOn at the top make sense: the first to run tasks in all sub-projects, and the second to make it convenient to debug stuff.

Now, the thing is that tests contains just a bunch of tests, and scripts is a script that is used as a publishing step -- so I need to somehow make it avoid making jar files only for them. I still want compile/test/etc to be aggregated including them.

My understanding from the docs is that this should be done by setting the aggregate key in Top, and indeed adding something like

  .settings(aggregate in clean:= false)

prevents clean from being aggregated -- but I want to do that for package and I don't want to drop it completely, just not package those two sub-projects. Using something like aggregate in (tests, packageBin) is my best guess, but that doesn't seem to make an impression on SBT: looks like packageBin is wrong, and also combining it with tests doesn't work.

Is that possible? Actually, given that SBT is just a tiny bit overengineered, it's always possible, so rephrase: How can I do that?

Update:

Thanks to this answer I found a workaround -- add:

.settings(Keys.`package` := file(""))

to the definitions of subprojects that shouldn't be packaged. That works for avoiding generation of jar files, but it's obviously not an answer for the actual question (which I'm probably going to run into again).

Outage answered 28/9, 2016 at 20:46 Comment(2)
I'm having the exact same question. Did you ever find a real answer?Shamblin
@akauppi: not really, but with the update I mentioned I managed to get around the problem...Outage

© 2022 - 2024 — McMap. All rights reserved.