diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 5c02b1a52..4c48a9ee4 100644 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -2614,6 +2614,7 @@ object Defaults extends BuildCommon { if (turbo.value) ClassLoaderLayeringStrategy.AllLibraryJars else ClassLoaderLayeringStrategy.ScalaLibrary }, + publishLocal / skip := (publish / skip).value, // So we don't break previous behaviour ) // build.sbt is treated a Scala source of metabuild, so to enable deprecation flag on build.sbt we set the option here. lazy val deprecationSettings: Seq[Setting[_]] = @@ -3585,15 +3586,57 @@ object Classpaths { ): Initialize[Task[Unit]] = publishTask(config) + private def logSkipPublish(log: Logger, ref: ProjectRef): Unit = + log.debug(s"Skipping publish* for ${ref.project}") + + private def checkAndPublishLocal( + currentCon: PublishConfiguration, + publishLocalConf: PublishConfiguration, + publishSkipLocal: Boolean, + module: IvySbt#Module, + log: Logger, + ref: ProjectRef + )(notPublishLocal: () => Unit): Unit = { + if (currentCon == publishLocalConf) { + if (publishSkipLocal) { + logSkipPublish(log, ref) + } else { + IvyActions.publish(module, currentCon, log) + } + } else { + notPublishLocal() + } + } + def publishTask(config: TaskKey[PublishConfiguration]): Initialize[Task[Unit]] = Def.taskIf { if ((publish / skip).value) { - val s = streams.value + val log = streams.value.log val ref = thisProjectRef.value - s.log.debug(s"Skipping publish* for ${ref.project}") + checkAndPublishLocal( + config.value, + publishLocalConfiguration.value, + (publishLocal / skip).value, + ivyModule.value, + log, + ref + ) { () => + logSkipPublish(log, ref) + } } else { - val s = streams.value - IvyActions.publish(ivyModule.value, config.value, s.log) + val conf = config.value + val log = streams.value.log + val module = ivyModule.value + checkAndPublishLocal( + conf, + publishLocalConfiguration.value, + (publishLocal / skip).value, + module, + log, + thisProjectRef.value + ) { () => + IvyActions.publish(module, conf, log) + } } } tag (Tags.Publish, Tags.Network) diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index 10ae7f1b1..c4b27364f 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -566,7 +566,7 @@ object Keys { val sbtDependency = settingKey[ModuleID]("Provides a definition for declaring the current version of sbt.").withRank(BMinusSetting) val sbtVersion = settingKey[String]("Provides the version of sbt. This setting should not be modified.").withRank(AMinusSetting) val sbtBinaryVersion = settingKey[String]("Defines the binary compatibility version substring.").withRank(BPlusSetting) - val skip = taskKey[Boolean]("For tasks that support it (currently only 'compile', 'update', and 'publish'), setting skip to true will force the task to not to do its work. This exact semantics may vary by task.").withRank(BSetting) + val skip = taskKey[Boolean]("For tasks that support it (currently only 'compile', 'update', 'publish' and 'publishLocal'), setting skip to true will force the task to not to do its work. This exact semantics may vary by task.").withRank(BSetting) val templateResolverInfos = settingKey[Seq[TemplateResolverInfo]]("Template resolvers used for 'new'.").withRank(BSetting) val interactionService = taskKey[InteractionService]("Service used to ask for user input through the current user interface(s).").withRank(CTask) val insideCI = SettingKey[Boolean]("insideCI", "Determines if the sbt is running in a Continuous Integration environment", AMinusSetting) diff --git a/sbt-app/src/sbt-test/project/skip/build.sbt b/sbt-app/src/sbt-test/project/skip/build.sbt new file mode 100644 index 000000000..72fed351d --- /dev/null +++ b/sbt-app/src/sbt-test/project/skip/build.sbt @@ -0,0 +1,20 @@ +publish / skip := true + +lazy val check = taskKey[Unit]("check") + +lazy val a = project + .in(file("a")) + .settings( + publishLocal / skip := true + ) + +lazy val b = project + .in(file("b")) + +check := { + assert((publishLocal / skip).value, "Expected true, got false") + assert((a / publishLocal / skip).value, "Expected true, got false") + assert(!(a / publish / skip).value, "Expected false, got true") + assert(!(b / publish / skip).value, "Expected false, got true") + assert(!(b / publishLocal / skip).value, "Expected false, got true") +} diff --git a/sbt-app/src/sbt-test/project/skip/test b/sbt-app/src/sbt-test/project/skip/test new file mode 100644 index 000000000..15675b169 --- /dev/null +++ b/sbt-app/src/sbt-test/project/skip/test @@ -0,0 +1 @@ +> check