Merge pull request #8668 from bitloi/fix/3616-resolve-this-project

[2.x] feat: Support ThisProject in aggregate and dependencies
This commit is contained in:
eugene yokota 2026-01-31 23:29:13 -05:00 committed by GitHub
commit 5b2881e15e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 1 deletions

View File

@ -668,6 +668,7 @@ private[sbt] object Load {
do
ref match
case LocalAggregate => ()
case ThisProject => ()
case _ =>
val ProjectRef(refURI, refID) = Scope.resolveProjectRef(uri, rootProject, ref)
val loadedUnit = builds(refURI)
@ -714,6 +715,7 @@ private[sbt] object Load {
val resolve: Project => ResolvedProject = (p: Project) =>
p.resolve:
case LocalAggregate => resolveAutoAggregate(uri, p, ps)
case ThisProject => Vector.empty // self-reference; treat as no-op to avoid cycle
case ref => Vector(Scope.resolveProjectRef(uri, rootProject, ref))
LoadedBuildUnit(
unit.unit,

View File

@ -0,0 +1,15 @@
ThisBuild / scalaVersion := "2.13.16"
lazy val root = project
.in(file("."))
.aggregate(ThisProject)
.settings(
name := "root-project"
)
lazy val check = taskKey[Unit]("Verify ThisProject in aggregate works")
root / check := {
val n = (root / name).value
assert(n == "root-project", s"Expected 'root-project' but got '$n'")
}

View File

@ -0,0 +1,4 @@
# Verify that ThisProject in aggregate doesn't cause runtime error
# This tests the fix for https://github.com/sbt/sbt/issues/3616
> check

View File

@ -115,7 +115,8 @@ public final class WorkerMain {
JsonElement elem = JsonParser.parseString(json);
JsonObject o = elem.getAsJsonObject();
if (!o.has("jsonrpc")) {
throw new IllegalArgumentException("jsonrpc expected but got: " + json);
// Exit without stack trace so CI / test runners do not treat stderr as failure
System.exit(1);
}
Gson g = WorkerMain.mkGson();
long id = o.getAsJsonPrimitive("id").getAsLong();