[2.x] fix dependency parsing for bsp (#9450)

This commit is contained in:
Anatolii Kmetiuk 2026-07-15 12:04:38 +09:00 committed by GitHub
parent da1a94bea9
commit 972d574750
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -22,9 +22,9 @@ private[sbt] object InternalDependencies {
((ref -> allConfigs) +:
projectDependencies.flatMap { case ClasspathDep.ResolvedClasspathDependency(p, rawConfigs) =>
val configs = rawConfigs.getOrElse("*->compile").split(";").flatMap { config =>
config.split("->") match {
case Array(n, c) if applicableConfigs.contains(n) => Some(c)
case Array(n) if applicableConfigs.contains(n) =>
config.split("->", 2).map(_.trim) match {
case Array(n, c) if c.nonEmpty && applicableConfigs.contains(n) => Some(c)
case Array(n) if applicableConfigs.contains(n) =>
// "test" is equivalent to "compile->test"
Some("compile")
case _ => None

View File

@ -4,6 +4,10 @@ lazy val b = project.in(file("b")).dependsOn(c)
lazy val c = project.in(file("c"))
lazy val d = project.in(file("d")).dependsOn(b % "test -> test")
lazy val e = project.in(file("e")).dependsOn(b % "test ->")
def getConfigs(key: SettingKey[Seq[(ProjectRef, Set[ConfigKey])]]):
Def.Initialize[Map[String, Set[String]]] =
Def.setting(key.value.map { case (p, c) => p.project -> c.map(_.name) }.toMap)
@ -16,4 +20,16 @@ TaskKey[Unit]("check") := {
"c" -> Set("compile")
)
assert(testDeps == expected)
val spacedTestDeps = getConfigs(d / Test / bspInternalDependencyConfigurations).value
val spacedExpected = Map(
"d" -> Set("compile", "test"),
"b" -> Set("compile", "test"),
"c" -> Set("compile")
)
assert(spacedTestDeps == spacedExpected, spacedTestDeps)
val emptyTargetDeps = getConfigs(e / Test / bspInternalDependencyConfigurations).value
val emptyTargetExpected = Map("e" -> Set("compile", "test"))
assert(emptyTargetDeps == emptyTargetExpected, emptyTargetDeps)
}