mirror of https://github.com/sbt/sbt.git
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:
parent
b834be8bfa
commit
a54777d4f2
|
|
@ -216,6 +216,7 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine {
|
||||||
private[sbt] def cachedResolutionResolveCache: CachedResolutionResolveCache
|
private[sbt] def cachedResolutionResolveCache: CachedResolutionResolveCache
|
||||||
private[sbt] def projectResolver: Option[ProjectResolver]
|
private[sbt] def projectResolver: Option[ProjectResolver]
|
||||||
private[sbt] def makeInstance: Ivy
|
private[sbt] def makeInstance: Ivy
|
||||||
|
private[sbt] val ignoreTransitiveForce: Boolean = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This returns sbt's UpdateReport structure.
|
* 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) =
|
def useLatest(lcm: LatestConflictManager): (Vector[ModuleReport], Vector[ModuleReport], String) =
|
||||||
(conflicts find { m =>
|
(conflicts find { m =>
|
||||||
m.callers.exists { _.isDirectlyForceDependency }
|
m.callers.exists { _.isDirectlyForceDependency }
|
||||||
} orElse (conflicts find { m =>
|
}) match {
|
||||||
m.callers.exists { _.isForceDependency }
|
|
||||||
})) match {
|
|
||||||
case Some(m) =>
|
case Some(m) =>
|
||||||
log.debug(s"- forced dependency: $m ${m.callers}")
|
log.debug(s"- directly forced dependency: $m ${m.callers}")
|
||||||
(Vector(m), conflicts filterNot { _ == m } map { _.copy(evicted = true, evictedReason = Some(lcm.toString)) }, lcm.toString)
|
(Vector(m), conflicts filterNot { _ == m } map { _.copy(evicted = true, evictedReason = Some("direct-force")) }, "direct-force")
|
||||||
case None =>
|
case None =>
|
||||||
val strategy = lcm.getStrategy
|
(conflicts find { m =>
|
||||||
val infos = conflicts map { ModuleReportArtifactInfo(_) }
|
m.callers.exists { _.isForceDependency }
|
||||||
Option(strategy.findLatest(infos.toArray, None.orNull)) match {
|
}) match {
|
||||||
case Some(ModuleReportArtifactInfo(m)) =>
|
// Ivy translates pom.xml dependencies to forced="true", so transitive force is broken.
|
||||||
(Vector(m), conflicts filterNot { _ == m } map { _.copy(evicted = true, evictedReason = Some(lcm.toString)) }, lcm.toString)
|
case Some(m) if !ignoreTransitiveForce =>
|
||||||
case _ => (conflicts, Vector(), lcm.toString)
|
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) =
|
def doResolveConflict: (Vector[ModuleReport], Vector[ModuleReport], String) =
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
lazy val check = taskKey[Unit]("Runs the check")
|
lazy val check = taskKey[Unit]("Runs the check")
|
||||||
lazy val check2 = taskKey[Unit]("Runs the check")
|
|
||||||
|
|
||||||
def commonSettings: Seq[Def.Setting[_]] =
|
def commonSettings: Seq[Def.Setting[_]] =
|
||||||
Seq(
|
Seq(
|
||||||
|
|
@ -37,20 +36,6 @@ lazy val c = project.
|
||||||
// libraryDependencies := Seq(organization.value %% "a" % version.value)
|
// 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(".")).
|
lazy val root = (project in file(".")).
|
||||||
settings(
|
settings(
|
||||||
organization in ThisBuild := "org.example",
|
organization in ThisBuild := "org.example",
|
||||||
|
|
@ -64,13 +49,5 @@ lazy val root = (project in file(".")).
|
||||||
"\n - a (cached) " + acp.toString +
|
"\n - a (cached) " + acp.toString +
|
||||||
"\n - b (plain) " + bcp.toString +
|
"\n - b (plain) " + bcp.toString +
|
||||||
"\n - c (inter-project) " + ccp.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)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,3 @@
|
||||||
> c/clean
|
> c/clean
|
||||||
|
|
||||||
> check
|
> check
|
||||||
|
|
||||||
> check2
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
> check
|
||||||
Loading…
Reference in New Issue