Fixes #1699. ignore transitive force during cached resolution

When Ivy translates pom to ivy.xml, it adds force=“true”.
So when both non-Maven dependencies and Maven dependencies are mixed, Maven dependencies always wins, which is the case for scala-library dependency added by the user.
This commit is contained in:
Eugene Yokota 2014-10-28 14:28:33 -04:00
parent b834be8bfa
commit a54777d4f2
5 changed files with 68 additions and 36 deletions

View File

@ -216,6 +216,7 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine {
private[sbt] def cachedResolutionResolveCache: CachedResolutionResolveCache
private[sbt] def projectResolver: Option[ProjectResolver]
private[sbt] def makeInstance: Ivy
private[sbt] val ignoreTransitiveForce: Boolean = true
/**
* This returns sbt's UpdateReport structure.
@ -339,19 +340,26 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine {
def useLatest(lcm: LatestConflictManager): (Vector[ModuleReport], Vector[ModuleReport], String) =
(conflicts find { m =>
m.callers.exists { _.isDirectlyForceDependency }
} orElse (conflicts find { m =>
m.callers.exists { _.isForceDependency }
})) match {
}) match {
case Some(m) =>
log.debug(s"- forced dependency: $m ${m.callers}")
(Vector(m), conflicts filterNot { _ == m } map { _.copy(evicted = true, evictedReason = Some(lcm.toString)) }, lcm.toString)
log.debug(s"- directly forced dependency: $m ${m.callers}")
(Vector(m), conflicts filterNot { _ == m } map { _.copy(evicted = true, evictedReason = Some("direct-force")) }, "direct-force")
case None =>
val strategy = lcm.getStrategy
val infos = conflicts map { ModuleReportArtifactInfo(_) }
Option(strategy.findLatest(infos.toArray, None.orNull)) match {
case Some(ModuleReportArtifactInfo(m)) =>
(Vector(m), conflicts filterNot { _ == m } map { _.copy(evicted = true, evictedReason = Some(lcm.toString)) }, lcm.toString)
case _ => (conflicts, Vector(), lcm.toString)
(conflicts find { m =>
m.callers.exists { _.isForceDependency }
}) match {
// Ivy translates pom.xml dependencies to forced="true", so transitive force is broken.
case Some(m) if !ignoreTransitiveForce =>
log.debug(s"- transitively forced dependency: $m ${m.callers}")
(Vector(m), conflicts filterNot { _ == m } map { _.copy(evicted = true, evictedReason = Some("transitive-force")) }, "transitive-force")
case _ =>
val strategy = lcm.getStrategy
val infos = conflicts map { ModuleReportArtifactInfo(_) }
Option(strategy.findLatest(infos.toArray, None.orNull)) match {
case Some(ModuleReportArtifactInfo(m)) =>
(Vector(m), conflicts filterNot { _ == m } map { _.copy(evicted = true, evictedReason = Some(lcm.toString)) }, lcm.toString)
case _ => (conflicts, Vector(), lcm.toString)
}
}
}
def doResolveConflict: (Vector[ModuleReport], Vector[ModuleReport], String) =

View File

@ -1,5 +1,4 @@
lazy val check = taskKey[Unit]("Runs the check")
lazy val check2 = taskKey[Unit]("Runs the check")
def commonSettings: Seq[Def.Setting[_]] =
Seq(
@ -37,20 +36,6 @@ lazy val c = project.
// libraryDependencies := Seq(organization.value %% "a" % version.value)
)
// overrides cached
lazy val d = project.
settings(consolidatedResolutionSettings: _*).
settings(
dependencyOverrides += "commons-io" % "commons-io" % "2.0"
)
// overrides plain
lazy val e = project.
settings(commonSettings: _*).
settings(
dependencyOverrides += "commons-io" % "commons-io" % "2.0"
)
lazy val root = (project in file(".")).
settings(
organization in ThisBuild := "org.example",
@ -64,13 +49,5 @@ lazy val root = (project in file(".")).
"\n - a (cached) " + acp.toString +
"\n - b (plain) " + bcp.toString +
"\n - c (inter-project) " + ccp.toString)
},
check2 := {
val dcp = (externalDependencyClasspath in Compile in d).value.sortBy {_.data.getName}
val ecp = (externalDependencyClasspath in Compile in e).value.sortBy {_.data.getName}
if (dcp == ecp) ()
else sys.error("Different classpaths are found:" +
"\n - d (overrides + cached) " + dcp.toString +
"\n - e (overrides + plain) " + ecp.toString)
}
)

View File

@ -11,5 +11,3 @@
> c/clean
> check
> check2

View File

@ -0,0 +1,48 @@
lazy val check = taskKey[Unit]("Runs the check")
def commonSettings: Seq[Def.Setting[_]] =
Seq(
ivyPaths := new IvyPaths( (baseDirectory in ThisBuild).value, Some((baseDirectory in LocalRootProject).value / "ivy-cache")),
dependencyCacheDirectory := (baseDirectory in LocalRootProject).value / "dependency",
libraryDependencies := Seq(
"net.databinder" %% "unfiltered-uploads" % "0.8.0",
"commons-io" % "commons-io" % "1.3",
"org.scala-refactoring" %% "org.scala-refactoring.library" % "0.6.2",
"org.scala-lang" % "scala-compiler" % scalaVersion.value
),
scalaVersion := "2.11.2",
resolvers += Resolver.sonatypeRepo("snapshots")
)
def consolidatedResolutionSettings: Seq[Def.Setting[_]] =
commonSettings ++ Seq(
updateOptions := updateOptions.value.withConsolidatedResolution(true)
)
// overrides cached
lazy val a = project.
settings(consolidatedResolutionSettings: _*).
settings(
dependencyOverrides += "commons-io" % "commons-io" % "2.0"
)
// overrides plain
lazy val b = project.
settings(commonSettings: _*).
settings(
dependencyOverrides += "commons-io" % "commons-io" % "2.0"
)
lazy val root = (project in file(".")).
settings(
organization in ThisBuild := "org.example",
version in ThisBuild := "1.0",
check := {
val acp = (externalDependencyClasspath in Compile in a).value.sortBy {_.data.getName}
val bcp = (externalDependencyClasspath in Compile in b).value.sortBy {_.data.getName}
if (acp == bcp) ()
else sys.error("Different classpaths are found:" +
"\n - a (overrides + cached) " + acp.toString +
"\n - b (overrides + plain) " + bcp.toString)
}
)

View File

@ -0,0 +1 @@
> check