mirror of https://github.com/sbt/sbt.git
Rely on coursier.Resolve to handle exclusions
It applies it to root dependencies too, in particular.
This commit is contained in:
parent
fa72797823
commit
3d374247ca
|
|
@ -25,14 +25,6 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
|||
* sbt-coursier, that was moved to this module.
|
||||
*/
|
||||
|
||||
private lazy val excludeDependencies = conf
|
||||
.excludeDependencies
|
||||
.map {
|
||||
case (strOrg, strName) =>
|
||||
(lmcoursier.definitions.Organization(strOrg), lmcoursier.definitions.ModuleName(strName))
|
||||
}
|
||||
.toSet
|
||||
|
||||
def moduleDescriptor(moduleSetting: ModuleDescriptorConfiguration): ModuleDescriptor =
|
||||
CoursierModuleDescriptor(moduleSetting, conf)
|
||||
|
||||
|
|
@ -125,8 +117,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
|||
}
|
||||
.map {
|
||||
case (config, dep) =>
|
||||
val dep0 = dep.withExclusions(dep.exclusions ++ excludeDependencies)
|
||||
(ToCoursier.configuration(config), ToCoursier.dependency(dep0))
|
||||
(ToCoursier.configuration(config), ToCoursier.dependency(dep))
|
||||
}
|
||||
|
||||
val orderedConfigs = Inputs.orderedConfigurations(Inputs.configExtendsSeq(module0.configurations))
|
||||
|
|
@ -145,6 +136,14 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
|||
.withCredentials(conf.credentials.map(ToCoursier.credentials))
|
||||
.withFollowHttpToHttpsRedirections(conf.followHttpToHttpsRedirections.getOrElse(true))
|
||||
|
||||
val excludeDependencies = conf
|
||||
.excludeDependencies
|
||||
.map {
|
||||
case (strOrg, strName) =>
|
||||
(coursier.Organization(strOrg), coursier.ModuleName(strName))
|
||||
}
|
||||
.toSet
|
||||
|
||||
val resolutionParams = ResolutionParams(
|
||||
dependencies = dependencies,
|
||||
fallbackDependencies = conf.fallbackDependencies,
|
||||
|
|
@ -164,7 +163,8 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
|||
.withProfiles(conf.mavenProfiles.toSet)
|
||||
.withForceVersion(conf.forceVersions.map { case (k, v) => (ToCoursier.module(k), v) }.toMap)
|
||||
.withTypelevel(typelevel)
|
||||
.withReconciliation(ToCoursier.reconciliation(conf.reconciliation)),
|
||||
.withReconciliation(ToCoursier.reconciliation(conf.reconciliation))
|
||||
.withExclusions(excludeDependencies),
|
||||
strictOpt = conf.strict.map(ToCoursier.strict),
|
||||
missingOk = conf.missingOk,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -28,32 +28,21 @@ object InputsTasks {
|
|||
private def coursierProject0(
|
||||
projId: ModuleID,
|
||||
dependencies: Seq[ModuleID],
|
||||
excludeDeps: Seq[InclExclRule],
|
||||
configurations: Seq[sbt.librarymanagement.Configuration],
|
||||
sv: String,
|
||||
sbv: String,
|
||||
log: Logger
|
||||
): Project = {
|
||||
|
||||
val exclusions0 = Inputs.exclusions(excludeDeps, sv, sbv, log)
|
||||
|
||||
val configMap = Inputs.configExtendsSeq(configurations).toMap
|
||||
|
||||
val proj = FromSbt.project(
|
||||
FromSbt.project(
|
||||
projId,
|
||||
dependencies,
|
||||
configMap,
|
||||
sv,
|
||||
sbv
|
||||
)
|
||||
|
||||
proj.withDependencies(
|
||||
proj.dependencies.map {
|
||||
case (config, dep) =>
|
||||
val dep0 = dep.withExclusions(dep.exclusions ++ exclusions0)
|
||||
(config, dep0)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private[sbtcoursiershared] def coursierProjectTask: Def.Initialize[sbt.Task[Project]] =
|
||||
|
|
@ -68,7 +57,6 @@ object InputsTasks {
|
|||
coursierProject0(
|
||||
projectID.in(projectRef).get(state),
|
||||
allDependenciesTask.value,
|
||||
actualExcludeDependencies.in(projectRef).get(state),
|
||||
// should projectID.configurations be used instead?
|
||||
ivyConfigurations.in(projectRef).get(state),
|
||||
scalaVersion.in(projectRef).get(state),
|
||||
|
|
|
|||
|
|
@ -114,6 +114,16 @@ object ResolutionTasks {
|
|||
.map(_.foldLeft[ProjectCache](Map.empty)(_ ++ _))
|
||||
.getOrElse(Map.empty)
|
||||
|
||||
val excludeDeps = Inputs.exclusions(
|
||||
coursier.sbtcoursiershared.InputsTasks.actualExcludeDependencies.value,
|
||||
sv,
|
||||
sbv,
|
||||
log
|
||||
).map {
|
||||
case (org, name) =>
|
||||
(Organization(org.value), ModuleName(name.value))
|
||||
}
|
||||
|
||||
val mainRepositories = resolvers
|
||||
.flatMap { resolver =>
|
||||
Resolvers.repository(
|
||||
|
|
@ -154,7 +164,8 @@ object ResolutionTasks {
|
|||
.withProfiles(userEnabledProfiles)
|
||||
.withForceVersion(userForceVersions.map { case (k, v) => (ToCoursier.module(k), v) }.toMap)
|
||||
.withTypelevel(typelevel)
|
||||
.addReconciliation(versionReconciliations0: _*),
|
||||
.addReconciliation(versionReconciliations0: _*)
|
||||
.withExclusions(excludeDeps),
|
||||
strictOpt = strictOpt,
|
||||
missingOk = missingOk,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
object Main extends App {
|
||||
|
||||
def classFound(clsName: String) = Try(
|
||||
Thread.currentThread()
|
||||
.getContextClassLoader()
|
||||
.loadClass(clsName)
|
||||
).toOption.nonEmpty
|
||||
|
||||
val shapelessFound = classFound("shapeless.HList")
|
||||
val argonautFound = classFound("argonaut.Json")
|
||||
val argonautShapelessFound = classFound("argonaut.derive.MkEncodeJson")
|
||||
|
||||
assert(
|
||||
argonautShapelessFound,
|
||||
"Expected to find class from argonaut-shapeless"
|
||||
)
|
||||
assert(
|
||||
!shapelessFound,
|
||||
"Expected not to find classes from shapeless"
|
||||
)
|
||||
assert(
|
||||
!argonautFound,
|
||||
"Expected not to find classes from argonaut"
|
||||
)
|
||||
}
|
||||
|
|
@ -1,11 +1,26 @@
|
|||
|
||||
scalaVersion := "2.12.8"
|
||||
lazy val a = project
|
||||
.settings(
|
||||
organization := "io.get-coursier.test",
|
||||
name := "sbt-coursier-exclude-dependencies",
|
||||
version := "0.1.0-SNAPSHOT",
|
||||
scalaVersion := "2.12.8",
|
||||
libraryDependencies += "com.github.alexarchambault" %% "argonaut-shapeless_6.2" % "1.2.0-M11",
|
||||
excludeDependencies += sbt.ExclusionRule("com.chuusai", "shapeless_2.12"),
|
||||
excludeDependencies += "io.argonaut" %% "argonaut"
|
||||
)
|
||||
|
||||
organization := "io.get-coursier.test"
|
||||
name := "sbt-coursier-exclude-dependencies"
|
||||
version := "0.1.0-SNAPSHOT"
|
||||
|
||||
libraryDependencies += "com.github.alexarchambault" %% "argonaut-shapeless_6.2" % "1.2.0-M11"
|
||||
|
||||
excludeDependencies += sbt.ExclusionRule("com.chuusai", "shapeless_2.12")
|
||||
excludeDependencies += "io.argonaut" %% "argonaut"
|
||||
lazy val b = project
|
||||
.settings(
|
||||
organization := "io.get-coursier.test",
|
||||
name := "sbt-coursier-exclude-dependencies-2",
|
||||
version := "0.1.0-SNAPSHOT",
|
||||
scalaVersion := "2.12.8",
|
||||
libraryDependencies ++= Seq(
|
||||
"com.github.alexarchambault" %% "argonaut-shapeless_6.2" % "1.2.0-M11",
|
||||
"com.chuusai" %% "shapeless" % "2.3.3",
|
||||
"io.argonaut" %% "argonaut" % "6.2.3"
|
||||
),
|
||||
excludeDependencies += sbt.ExclusionRule("com.chuusai", "shapeless_2.12"),
|
||||
excludeDependencies += "io.argonaut" %% "argonaut"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
> run
|
||||
> publishLocal
|
||||
> a/run
|
||||
> a/publishLocal
|
||||
$ exec java -jar coursier launch io.get-coursier.test:sbt-coursier-exclude-dependencies_2.12:0.1.0-SNAPSHOT
|
||||
> b/run
|
||||
> b/publishLocal
|
||||
# doesn't pass yet (missing exclusions of root deps in ivy.xml?)
|
||||
# $ exec java -jar coursier launch io.get-coursier.test:sbt-coursier-exclude-dependencies-2_2.12:0.1.0-SNAPSHOT
|
||||
|
|
|
|||
Loading…
Reference in New Issue