mirror of https://github.com/sbt/sbt.git
Fix provided scope handling (#239)
It was resolved independently of compile since we run resolutions for each configuration. It couldn't bump versions in compile because of that in particular.
This commit is contained in:
parent
b82f3a2746
commit
031648a1d7
|
|
@ -53,7 +53,9 @@ import scala.concurrent.duration.Duration
|
|||
@since
|
||||
missingOk: Boolean = false,
|
||||
@since
|
||||
sbtClassifiers: Boolean = false
|
||||
sbtClassifiers: Boolean = false,
|
||||
@since
|
||||
providedInCompile: Boolean = true
|
||||
) {
|
||||
|
||||
def withLog(log: Logger): CoursierConfiguration =
|
||||
|
|
|
|||
|
|
@ -144,10 +144,15 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
|||
}
|
||||
.toSet
|
||||
|
||||
val providedOpt = orderedConfigs.collectFirst {
|
||||
case (c, _) if conf.providedInCompile && c.value.equalsIgnoreCase("provided") => c
|
||||
}
|
||||
|
||||
val resolutionParams = ResolutionParams(
|
||||
dependencies = dependencies,
|
||||
fallbackDependencies = conf.fallbackDependencies,
|
||||
orderedConfigs = orderedConfigs,
|
||||
orderedConfigs = providedOpt.fold(orderedConfigs)(provided => orderedConfigs.filter(_._1 != provided)),
|
||||
subConfigs = providedOpt.map(_ -> coursier.core.Configuration.compile).toSeq,
|
||||
autoScalaLibOpt = if (conf.autoScalaLibrary) Some((so, sv)) else None,
|
||||
mainRepositories = mainRepositories,
|
||||
parentProjectCache = Map.empty,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ final case class ResolutionParams(
|
|||
dependencies: Seq[(Configuration, Dependency)],
|
||||
fallbackDependencies: Seq[FallbackDependency],
|
||||
orderedConfigs: Seq[(Configuration, Seq[Configuration])],
|
||||
subConfigs: Seq[(Configuration, Configuration)],
|
||||
autoScalaLibOpt: Option[(Organization, String)],
|
||||
mainRepositories: Seq[Repository],
|
||||
parentProjectCache: ProjectCache,
|
||||
|
|
@ -34,12 +35,18 @@ final case class ResolutionParams(
|
|||
|
||||
lazy val allConfigExtends: Map[Configuration, Set[Configuration]] = {
|
||||
val map = new mutable.HashMap[Configuration, Set[Configuration]]
|
||||
val subConfigMap = subConfigs
|
||||
.map { case (config, parent) => parent -> config }
|
||||
.groupBy(_._1)
|
||||
.mapValues(_.map(_._2))
|
||||
.toMap
|
||||
for ((config, extends0) <- orderedConfigs) {
|
||||
val allExtends = extends0
|
||||
.iterator
|
||||
// the else of the getOrElse shouldn't be hit (because of the ordering of the configurations)
|
||||
.foldLeft(Set(config))((acc, ext) => acc ++ map.getOrElse(ext, Set(ext)))
|
||||
map += config -> allExtends
|
||||
val viaSubConfig = subConfigMap.getOrElse(config, Nil)
|
||||
map += config -> (allExtends ++ viaSubConfig)
|
||||
}
|
||||
map.toMap
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,6 +163,31 @@ object ResolutionRun {
|
|||
()
|
||||
}
|
||||
}
|
||||
val withSubResolutions = params.subConfigs.foldLeft(either) {
|
||||
case (acc, (config, parent)) =>
|
||||
for {
|
||||
_ <- acc
|
||||
initResOpt = map.get(parent)
|
||||
allExtends = params.allConfigExtends.getOrElse(config, Set.empty)
|
||||
res <- {
|
||||
initResOpt match {
|
||||
case None =>
|
||||
val allExtendsWithParent = allExtends ++
|
||||
params.allConfigExtends.getOrElse(parent, Set.empty)
|
||||
resolution(params, verbosityLevel, log, allExtendsWithParent, None)
|
||||
case Some(initRes) =>
|
||||
val deps = params.dependencies.collect {
|
||||
case (config, dep) if allExtends(config) =>
|
||||
dep
|
||||
}
|
||||
Right(initRes.subset(deps))
|
||||
}
|
||||
}
|
||||
} yield {
|
||||
map += config -> res
|
||||
()
|
||||
}
|
||||
}
|
||||
either.map(_ => map.toMap)
|
||||
}
|
||||
for (res <- resOrError)
|
||||
|
|
|
|||
|
|
@ -138,11 +138,16 @@ object ResolutionTasks {
|
|||
)
|
||||
}
|
||||
|
||||
val providedOpt = orderedConfigs.collectFirst {
|
||||
case (c, _) if c.value.equalsIgnoreCase("provided") => c
|
||||
}
|
||||
|
||||
val resOrError = ResolutionRun.resolutions(
|
||||
ResolutionParams(
|
||||
dependencies = currentProject.dependencies,
|
||||
fallbackDependencies = fallbackDependencies,
|
||||
orderedConfigs = orderedConfigs,
|
||||
subConfigs = providedOpt.map(_ -> coursier.core.Configuration.compile).toSeq,
|
||||
autoScalaLibOpt = if (autoScalaLib) Some((so, sv)) else None,
|
||||
mainRepositories = mainRepositories,
|
||||
parentProjectCache = parentProjectCache,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
libraryDependencies ++= Seq(
|
||||
"com.github.alexarchambault" %% "argonaut-shapeless_6.2" % "1.2.0-M5",
|
||||
"com.chuusai" %% "shapeless" % "2.3.3" % Provided
|
||||
)
|
||||
scalaVersion := "2.12.11"
|
||||
|
||||
lazy val check = taskKey[Unit]("")
|
||||
|
||||
check := {
|
||||
|
||||
val updateReport = update.value
|
||||
|
||||
def checkVersions(config: Configuration): Unit = {
|
||||
|
||||
val configReport = updateReport
|
||||
.configuration(Compile)
|
||||
.getOrElse {
|
||||
throw new Exception(
|
||||
s"$config configuration not found in update report"
|
||||
)
|
||||
}
|
||||
|
||||
val shapelessVersions = configReport
|
||||
.modules
|
||||
.map(_.module)
|
||||
.collect {
|
||||
case m if m.organization == "com.chuusai" && m.name.startsWith("shapeless") =>
|
||||
m.revision
|
||||
}
|
||||
.toSet
|
||||
|
||||
val expectedShapelessVersions = Set("2.3.3")
|
||||
assert(
|
||||
shapelessVersions == expectedShapelessVersions,
|
||||
s"Expected shapeless versions $expectedShapelessVersions, got $shapelessVersions"
|
||||
)
|
||||
}
|
||||
|
||||
checkVersions(Compile)
|
||||
checkVersions(Provided)
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
addSbtPlugin {
|
||||
|
||||
val name = sys.props.getOrElse(
|
||||
"plugin.name",
|
||||
sys.error("plugin.name Java property not set")
|
||||
)
|
||||
val version = sys.props.getOrElse(
|
||||
"plugin.version",
|
||||
sys.error("plugin.version Java property not set")
|
||||
)
|
||||
|
||||
"io.get-coursier" % name % version
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
> check
|
||||
Loading…
Reference in New Issue