How to disable package and publish tasks for root aggregate module in multi-module build?

Instead of playing whac-a-mole by listing specific tasks to disable (publish, publish-local, publish-signed, etc), another option is to turn off artifact publishing at the source.

publishArtifact := false

Even though there's no publishing happening, I also found I needed to supply a publishTo value to make sbt-pgp's publish-signed task happy. It needs this value, even if it never uses it.

publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo")))

Actually, it is pretty easy. Just override the setting for publish in the root project:

base = file(".")) settings (publish := { }) aggregate(foo, bar)

The following worked for me (this can also be used in other sub projects):

lazy val root = Project(
  id = "root",
  base = file("."),
  aggregate = Seq(foo, bar),
  settings = Project.defaultSettings ++ Seq(
    publishLocal := {},
    publish := {}
  )
)

(sbt 0.12.2)

Tags:

Scala

Sbt