Skip to content

Commit 3afc15d

Browse files
authored
Merge pull request #69 from sbt/fport/2642
[fport] Fixes merged ModuleID dropping configuration specification
2 parents 9dd1dff + df53eef commit 3afc15d

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

librarymanagement/src/main/scala/sbt/internal/librarymanagement/ivyint/MergeDescriptors.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private[sbt] object MergeDescriptors {
3131

3232
// combines the artifacts, configurations, includes, and excludes for DependencyDescriptors `a` and `b`
3333
// that otherwise have equal IDs
34-
private final class MergedDescriptors(a: DependencyDescriptor, b: DependencyDescriptor) extends DependencyDescriptor {
34+
private[sbt] final case class MergedDescriptors(a: DependencyDescriptor, b: DependencyDescriptor) extends DependencyDescriptor {
3535
def getDependencyId = a.getDependencyId
3636
def isForce = a.isForce
3737
def isChanging = a.isChanging
@@ -80,11 +80,14 @@ private final class MergedDescriptors(a: DependencyDescriptor, b: DependencyDesc
8080
arts map { art => explicitConfigurations(base, art) }
8181
private[this] def explicitConfigurations(base: DependencyDescriptor, art: DependencyArtifactDescriptor): DependencyArtifactDescriptor =
8282
{
83-
val aConfs = art.getConfigurations
84-
if (aConfs == null || aConfs.isEmpty)
85-
copyWithConfigurations(art, base.getModuleConfigurations)
86-
else
87-
art
83+
val aConfs = Option(art.getConfigurations) map { _.toList }
84+
// In case configuration list is "*", we should still specify the module configuration of the DependencyDescriptor
85+
// otherwise the explicit specified artifacts from one dd can leak over to the other.
86+
// See gh-1500, gh-2002
87+
aConfs match {
88+
case None | Some(Nil) | Some(List("*")) => copyWithConfigurations(art, base.getModuleConfigurations)
89+
case _ => art
90+
}
8891
}
8992
private[this] def defaultArtifact(a: DependencyDescriptor): Array[DependencyArtifactDescriptor] =
9093
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package sbt.internal.librarymanagement
2+
3+
import org.apache.ivy.core.module.descriptor.{ DependencyArtifactDescriptor }
4+
import sbt.librarymanagement._
5+
import sbt.internal.librarymanagement.ivyint._
6+
7+
class MergeDescriptorSpec extends BaseIvySpecification {
8+
"Merging duplicate dependencies" should "work" in {
9+
cleanIvyCache()
10+
val m = module(
11+
ModuleID("com.example", "foo", "0.1.0").withConfigurations(Some("compile")),
12+
Vector(guavaTest, guavaTestTests), None, UpdateOptions()
13+
)
14+
m.withModule(log) {
15+
case (ivy, md, _) =>
16+
val deps = md.getDependencies
17+
assert(deps.size == 1)
18+
deps.headOption.getOrElse(sys.error("Dependencies not found")) match {
19+
case dd @ MergedDescriptors(dd0, dd1) =>
20+
val arts = dd.getAllDependencyArtifacts
21+
val a0: DependencyArtifactDescriptor = arts.toList(0)
22+
val a1: DependencyArtifactDescriptor = arts.toList(1)
23+
val configs0 = a0.getConfigurations.toList
24+
val configs1 = a1.getConfigurations.toList
25+
configs0 shouldEqual List("compile")
26+
configs1 shouldEqual List("test")
27+
}
28+
}
29+
}
30+
def guavaTest = ModuleID("com.google.guava", "guava-tests", "18.0").withConfigurations(Option("compile"))
31+
def guavaTestTests = ModuleID("com.google.guava", "guava-tests", "18.0").withConfigurations(Option("test")).classifier("tests")
32+
def defaultOptions = EvictionWarningOptions.default
33+
34+
}

0 commit comments

Comments
 (0)