Skip to content

Commit

Permalink
Fixes sbt#1634. Adds inconsistent duplicate warning
Browse files Browse the repository at this point in the history
sbt#1634 is about a library getting wiped out of deps graph when it’s
included twice in ascending order of version.
I’d say that’s a logically inconsistent state, and we should just issue
warning instead of trying to fix it.
  • Loading branch information
eed3si9n committed Dec 14, 2014
1 parent af123e7 commit 9d09af9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ivy/src/main/scala/sbt/Ivy.scala
Expand Up @@ -527,6 +527,29 @@ private[sbt] object IvySbt {
parser
}

def inconsistentDuplicateWarning(moduleID: DefaultModuleDescriptor): List[String] =
{
import IvyRetrieve.toModuleID
val dds = moduleID.getDependencies
inconsistentDuplicateWarning(dds map { dd => toModuleID(dd.getDependencyRevisionId) })
}

def inconsistentDuplicateWarning(dependencies: Seq[ModuleID]): List[String] =
{
val warningHeader = "Multiple dependencies with the same organization/name but different versions. To avoid conflict, pick one version:"
val out: mutable.ListBuffer[String] = mutable.ListBuffer()
(dependencies groupBy { dep => (dep.organization, dep.name) }) foreach {
case (k, vs) if vs.size > 1 =>
val v0 = vs.head
(vs find { _.revision != v0.revision }) foreach { v =>
out += s" * ${v0.organization}:${v0.name}:(" + (vs map { _.revision }).mkString(", ") + ")"
}
case _ => ()
}
if (out.isEmpty) Nil
else warningHeader :: out.toList
}

/** This method is used to add inline dependencies to the provided module. */
def addDependencies(moduleID: DefaultModuleDescriptor, dependencies: Seq[ModuleID], parser: CustomXmlParser.CustomParser) {
val converted = dependencies map { dependency => convertDependency(moduleID, dependency, parser) }
Expand Down
4 changes: 4 additions & 0 deletions ivy/src/main/scala/sbt/IvyActions.scala
Expand Up @@ -166,6 +166,8 @@ object IvyActions {
case (ivy, md, default) if module.owner.configuration.updateOptions.cachedResolution && depDir.isDefined =>
ivy.getResolveEngine match {
case x: CachedResolutionResolveEngine =>
val iw = IvySbt.inconsistentDuplicateWarning(md)
iw foreach { log.warn(_) }
val resolveOptions = new ResolveOptions
val resolveId = ResolveOptions.getDefaultResolveId(md)
resolveOptions.setResolveId(resolveId)
Expand All @@ -181,6 +183,8 @@ object IvyActions {
}
}
case (ivy, md, default) =>
val iw = IvySbt.inconsistentDuplicateWarning(md)
iw foreach { log.warn(_) }
val (report, err) = resolve(configuration.logging)(ivy, md, default)
err match {
case Some(x) if !configuration.missingOk =>
Expand Down
28 changes: 28 additions & 0 deletions ivy/src/test/scala/InconsistentDuplicateSpec.scala
@@ -0,0 +1,28 @@
package sbt

import org.specs2._

class InconsistentDuplicateSpec extends Specification {
def is = s2"""

This is a specification to check the inconsistent duplicate warnings

Duplicate with different version should
be warned $warn1

Duplicate with same version should
not be warned $nodupe1
"""

def akkaActor214 = ModuleID("com.typesafe.akka", "akka-actor", "2.1.4", Some("compile")) cross CrossVersion.binary
def akkaActor230 = ModuleID("com.typesafe.akka", "akka-actor", "2.3.0", Some("compile")) cross CrossVersion.binary
def akkaActor230Test = ModuleID("com.typesafe.akka", "akka-actor", "2.3.0", Some("test")) cross CrossVersion.binary

def warn1 =
IvySbt.inconsistentDuplicateWarning(Seq(akkaActor214, akkaActor230)) must_==
List("Multiple dependencies with the same organization/name but different versions. To avoid conflict, pick one version:",
" * com.typesafe.akka:akka-actor:(2.1.4, 2.3.0)")

def nodupe1 =
IvySbt.inconsistentDuplicateWarning(Seq(akkaActor230Test, akkaActor230)) must_== Nil
}
13 changes: 13 additions & 0 deletions notes/0.13.8/inconsistent-duplicates.markdown
@@ -0,0 +1,13 @@
[@cunei]: https://github.com/cunei
[@eed3si9n]: https://github.com/eed3si9n
[@gkossakowski]: https://github.com/gkossakowski
[@jsuereth]: https://github.com/jsuereth
[1634]: https://github.com/sbt/sbt/pull/1634

### Fixes with compatibility implications

### Improvements

### Bug fixes

- Issues warning if multiple dependencies to a same library is found with different version. [#1634][1634] by [@eed3si9n][@eed3si9n]

0 comments on commit 9d09af9

Please sign in to comment.