From 90770b6ad181985d2087ca2e9b7d46af65c6d32b Mon Sep 17 00:00:00 2001 From: eugene yokota Date: Sun, 5 Apr 2026 00:52:29 -0400 Subject: [PATCH] [2.x] fix: Fixes pollInterval (#9020) **Problem/Solution** checkBuildSources / pollInterval should just fallback to some value. --- main/src/main/scala/sbt/Defaults.scala | 5 ++--- main/src/main/scala/sbt/nio/CheckBuildSources.scala | 11 ++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 2ab3dc3e6..266b37e5f 100644 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -418,6 +418,7 @@ object Defaults extends BuildCommon with DefExtra { terminal := Def.uncached(state.value.get(terminalKey).getOrElse(Terminal(ITerminal.get))), InstallSbtn.installSbtn := InstallSbtn.installSbtnImpl.evaluated, InstallSbtn.installSbtn / aggregate := false, + checkBuildSources / pollInterval :== CheckBuildSources.defaultPollInterval, ) ++ LintUnused.lintSettings ++ DefaultBackgroundJobService.backgroundJobServiceSettings ++ RemoteCache.globalSettings @@ -553,8 +554,6 @@ object Defaults extends BuildCommon with DefExtra { sourceManaged := target.value / "src_managed", resourceManaged := target.value / "resource_managed", // Adds subproject build.sbt files to the global list of build files to monitor - Scope.Global / checkBuildSources / pollInterval :== - new FiniteDuration(Int.MinValue, TimeUnit.MILLISECONDS), Scope.Global / checkBuildSources / fileInputs ++= { if ((Scope.Global / onChangedBuildSource).value != IgnoreSourceChanges) Seq(baseDirectory.value.toGlob / "*.sbt") @@ -3387,7 +3386,7 @@ object Classpaths { maybeUpdateRemoteProjects := Def.uncached(Def.taskDyn { val buildDeps = buildDependencies.value val thisRef = thisProjectRef.value - val lb = Project.extract(state.value).get(Keys.loadedBuild) + val lb = loadedBuild.value val vcsRootRefs = Resolvers.transitiveVcsRootRefs(thisRef, buildDeps, lb) if (vcsRootRefs.isEmpty) Def.task(()) else Def.sequential(vcsRootRefs.map(_ / fetchSource).toSeq) diff --git a/main/src/main/scala/sbt/nio/CheckBuildSources.scala b/main/src/main/scala/sbt/nio/CheckBuildSources.scala index 7b3bde263..1a39546d3 100644 --- a/main/src/main/scala/sbt/nio/CheckBuildSources.scala +++ b/main/src/main/scala/sbt/nio/CheckBuildSources.scala @@ -10,6 +10,7 @@ package sbt package internal.nio import java.nio.file.Path +import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference } import sbt.BasicCommandStrings.{ RebootCommand, Shutdown, TerminateAction } import sbt.Keys.{ baseDirectory, pollInterval, state } @@ -65,7 +66,9 @@ private[sbt] class CheckBuildSources extends AutoCloseable { } private def reset(state: State): Unit = { val extracted = Project.extract(state) - val interval = extracted.get(checkBuildSources / pollInterval) + val interval = extracted + .getOpt(checkBuildSources / pollInterval) + .getOrElse(CheckBuildSources.defaultPollInterval) val newSources = extracted.get(Global / checkBuildSources / fileInputs).distinct if (interval >= 0.seconds || "polling" == SysProp.watchMode) { Option(repository.getAndSet(null)).foreach(_.close()) @@ -174,7 +177,9 @@ private[sbt] class CheckBuildSources extends AutoCloseable { override def close(): Unit = {} } -private[sbt] object CheckBuildSources { +private[sbt] object CheckBuildSources: + val defaultPollInterval: FiniteDuration = FiniteDuration(Int.MinValue, TimeUnit.MILLISECONDS) + private[sbt] val CheckBuildSourcesKey = AttributeKey[CheckBuildSources]("check-build-source", "", KeyRanks.Invisible) /* @@ -219,4 +224,4 @@ private[sbt] object CheckBuildSources { projectGlobs(projectDir, baseDir.toGlob / "*.sbt" :: Nil) } else Nil } -} +end CheckBuildSources