Improve deprecation UX for watchSources (#9247)

This commit is contained in:
Anatolii Kmetiuk 2026-05-20 09:44:51 +09:00 committed by GitHub
parent 696626e195
commit 03965281df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 4 deletions

View File

@ -333,7 +333,8 @@ object Defaults extends BuildCommon with DefExtra {
new AppenderSupplier:
def apply(s: ScopedKey[?]): Seq[Appender] = Nil
},
watchSources :== Nil, // Although this is deprecated, it can't be removed or it breaks += for legacy builds.
// Although this is deprecated, it can't be removed or it breaks += for legacy builds.
((watchSources :== Nil): @nowarn("cat=deprecation")),
skip :== false,
taskTemporaryDirectory := {
val base = BuildPaths.globalTaskDirectoryStandard(appConfiguration.value.baseDirectory)

View File

@ -138,6 +138,11 @@ object Keys {
val watchService = settingKey[() => WatchService]("Service to use to monitor file system changes.").withRank(BMinusSetting).withRank(DSetting)
// Deprecated watch apis
@transient
@deprecated(
"watchSources is deprecated; use fileInputs for task inputs or watchTriggers for extra continuous-build triggers.",
"2.0.0"
)
val watchSources = taskKey[Seq[Watched.WatchSource]]("Defines the sources in this project for continuous execution to watch for changes.").withRank(BMinusSetting)
// Path Keys

View File

@ -21,7 +21,7 @@ import sbt.nio.FileStamper
import sbt.nio.Keys.*
import sbt.nio.file.Glob
import scala.annotation.tailrec
import scala.annotation.{ nowarn, tailrec }
private[sbt] object WatchTransitiveDependencies {
extension (source: Source) {
@ -157,7 +157,7 @@ private[sbt] object WatchTransitiveDependencies {
data.scopes.toSeq
.withFilter(s => s == Scope.Global || s.project.toOption.exists(projects.contains))
.flatMap { s =>
data.getDirect(ScopedKey(s, Keys.watchSources.key)).map { task =>
data.getDirect(legacyWatchSourcesScopedKey(s)).map { task =>
task.work match
case a: Action.Pure[Seq[Watched.WatchSource]] => Right(a.f().map(_.toGlob))
case _ => Left(s)
@ -167,11 +167,22 @@ private[sbt] object WatchTransitiveDependencies {
DynamicInput(glob, FileStamper.LastModified, forceTrigger = true)
scopes.flatMap {
case Left(scope) =>
extracted.runTask(scope / Keys.watchSources, state)._2.map(s => toDynamicInput(s.toGlob))
extracted
.runTask(legacyWatchSourcesTask(scope), state)
._2
.map(s => toDynamicInput(s.toGlob))
case Right(globs) => globs.map(toDynamicInput)
}
}
private def legacyWatchSourcesScopedKey(
scope: Scope
): ScopedKey[Task[Seq[Watched.WatchSource]]] =
(ScopedKey(scope, Keys.watchSources.key): @nowarn("cat=deprecation"))
private def legacyWatchSourcesTask(scope: Scope): TaskKey[Seq[Watched.WatchSource]] =
(scope / Keys.watchSources: @nowarn("cat=deprecation"))
@tailrec
private def collectKeys(
arguments: Arguments,

View File

@ -0,0 +1 @@
watchSources += file("foo")

View File

@ -0,0 +1 @@
> show watchSources