[2.x] Disable delegation on shell (#8539)

**Problem**
Currently the shell delegates request tasks even when a non-existent
task like Compile / update is requested.

**Solution**
This removes the delegation, if the input key is scoped, so it will fail.
We will, however, continue to delegate on the subproject axis,
since it's useful to use Global or ThisBuild scoping.
This commit is contained in:
eugene yokota 2026-01-17 00:05:21 -05:00 committed by GitHub
parent c832fad7b5
commit 8b4b89c395
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 1 deletions

View File

@ -573,8 +573,14 @@ object Act {
private def anyKeyValues(structure: BuildStructure, keys: Seq[ScopedKey[?]]): Seq[KeyValue[?]] =
keys.flatMap(key => getValue(structure.data, key).map(KeyValue(key, _)))
/**
* Starting sbt 2.0.0, we will not delegate when a non-existent scoping
* such as Compile / update is required.
*/
private def getValue[T](data: Def.Settings, key: ScopedKey[T]): Option[T] =
if (java.lang.Boolean.getBoolean("sbt.cli.nodelegation")) data.getDirect(key)
if key.scope.config.isSelect ||
key.scope.task.isSelect
then data.getDirect(key)
else data.get(key)
def requireSession[T](s: State, p: => Parser[T]): Parser[T] =

View File

@ -0,0 +1 @@
scalaVersion := "3.7.4"

View File

@ -0,0 +1,6 @@
> compile
> test
# Fail on non-existent scoping
-> Compile / update