mirror of https://github.com/sbt/sbt.git
Handle ThisProject in aggregate and dependencies
Fixes #3616 - Scope's resolveProjectBuild and resolveProjectRef mishandle ThisProject. Previously, using ThisProject in aggregate() or dependsOn() would cause a runtime error: 'Cannot resolve ThisProject w/o the current project'. This change adds proper handling for ThisProject in Load.scala: - In checkAll: Skip validation for ThisProject (refers to self) - In resolveProjects: Resolve ThisProject to ProjectRef(uri, p.id)
This commit is contained in:
parent
a6e4c9c3c1
commit
1a6039c17a
|
|
@ -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(ProjectRef(uri, p.id))
|
||||
case ref => Vector(Scope.resolveProjectRef(uri, rootProject, ref))
|
||||
LoadedBuildUnit(
|
||||
unit.unit,
|
||||
|
|
|
|||
|
|
@ -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'")
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Verify that ThisProject in aggregate doesn't cause runtime error
|
||||
# This tests the fix for https://github.com/sbt/sbt/issues/3616
|
||||
> check
|
||||
Loading…
Reference in New Issue