diff --git a/main/src/main/scala/sbt/internal/InternalDependencies.scala b/main/src/main/scala/sbt/internal/InternalDependencies.scala index 9dc447831..6808f5e6a 100644 --- a/main/src/main/scala/sbt/internal/InternalDependencies.scala +++ b/main/src/main/scala/sbt/internal/InternalDependencies.scala @@ -14,19 +14,21 @@ private[sbt] object InternalDependencies { def configurations: Def.Initialize[Seq[(ProjectRef, Set[String])]] = Def.setting { val allConfigs = Classpaths.allConfigs(configuration.value).map(_.name).toSet val ref = thisProjectRef.value + val projectDependencies = buildDependencies.value.classpath.get(ref).toSeq.flatten val applicableConfigs = allConfigs + "*" - ((ref -> allConfigs) +: buildDependencies.value.classpath - .get(ref) - .toSeq - .flatMap(_.flatMap { + ((ref -> allConfigs) +: + projectDependencies.flatMap { case 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 _ => None + case Array(n) if applicableConfigs.contains(n) => + // "test" is equivalent to "compile->test" + Some("compile") + case _ => None } } if (configs.isEmpty) None else Some(p -> configs.toSet) - })).distinct + }).distinct } } diff --git a/sbt/src/sbt-test/project/bsp-internal-dependency-configs/build.sbt b/sbt/src/sbt-test/project/bsp-internal-dependency-configs/build.sbt new file mode 100644 index 000000000..bc3f2d431 --- /dev/null +++ b/sbt/src/sbt-test/project/bsp-internal-dependency-configs/build.sbt @@ -0,0 +1,19 @@ +lazy val a = project.in(file("a")).dependsOn(b % Test) + +lazy val b = project.in(file("b")).dependsOn(c) + +lazy val c = project.in(file("c")) + +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) + +TaskKey[Unit]("check") := { + val testDeps = getConfigs(a / Test / bspInternalDependencyConfigurations).value + val expected = Map( + "a" -> Set("compile", "test"), + "b" -> Set("compile"), + "c" -> Set("compile") + ) + assert(testDeps == expected) +} diff --git a/sbt/src/sbt-test/project/bsp-internal-dependency-configs/test b/sbt/src/sbt-test/project/bsp-internal-dependency-configs/test new file mode 100644 index 000000000..15675b169 --- /dev/null +++ b/sbt/src/sbt-test/project/bsp-internal-dependency-configs/test @@ -0,0 +1 @@ +> check