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.
|
* 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 =
|
def moduleDescriptor(moduleSetting: ModuleDescriptorConfiguration): ModuleDescriptor =
|
||||||
CoursierModuleDescriptor(moduleSetting, conf)
|
CoursierModuleDescriptor(moduleSetting, conf)
|
||||||
|
|
||||||
|
|
@ -125,8 +117,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
||||||
}
|
}
|
||||||
.map {
|
.map {
|
||||||
case (config, dep) =>
|
case (config, dep) =>
|
||||||
val dep0 = dep.withExclusions(dep.exclusions ++ excludeDependencies)
|
(ToCoursier.configuration(config), ToCoursier.dependency(dep))
|
||||||
(ToCoursier.configuration(config), ToCoursier.dependency(dep0))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val orderedConfigs = Inputs.orderedConfigurations(Inputs.configExtendsSeq(module0.configurations))
|
val orderedConfigs = Inputs.orderedConfigurations(Inputs.configExtendsSeq(module0.configurations))
|
||||||
|
|
@ -145,6 +136,14 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
||||||
.withCredentials(conf.credentials.map(ToCoursier.credentials))
|
.withCredentials(conf.credentials.map(ToCoursier.credentials))
|
||||||
.withFollowHttpToHttpsRedirections(conf.followHttpToHttpsRedirections.getOrElse(true))
|
.withFollowHttpToHttpsRedirections(conf.followHttpToHttpsRedirections.getOrElse(true))
|
||||||
|
|
||||||
|
val excludeDependencies = conf
|
||||||
|
.excludeDependencies
|
||||||
|
.map {
|
||||||
|
case (strOrg, strName) =>
|
||||||
|
(coursier.Organization(strOrg), coursier.ModuleName(strName))
|
||||||
|
}
|
||||||
|
.toSet
|
||||||
|
|
||||||
val resolutionParams = ResolutionParams(
|
val resolutionParams = ResolutionParams(
|
||||||
dependencies = dependencies,
|
dependencies = dependencies,
|
||||||
fallbackDependencies = conf.fallbackDependencies,
|
fallbackDependencies = conf.fallbackDependencies,
|
||||||
|
|
@ -164,7 +163,8 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
|
||||||
.withProfiles(conf.mavenProfiles.toSet)
|
.withProfiles(conf.mavenProfiles.toSet)
|
||||||
.withForceVersion(conf.forceVersions.map { case (k, v) => (ToCoursier.module(k), v) }.toMap)
|
.withForceVersion(conf.forceVersions.map { case (k, v) => (ToCoursier.module(k), v) }.toMap)
|
||||||
.withTypelevel(typelevel)
|
.withTypelevel(typelevel)
|
||||||
.withReconciliation(ToCoursier.reconciliation(conf.reconciliation)),
|
.withReconciliation(ToCoursier.reconciliation(conf.reconciliation))
|
||||||
|
.withExclusions(excludeDependencies),
|
||||||
strictOpt = conf.strict.map(ToCoursier.strict),
|
strictOpt = conf.strict.map(ToCoursier.strict),
|
||||||
missingOk = conf.missingOk,
|
missingOk = conf.missingOk,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -28,32 +28,21 @@ object InputsTasks {
|
||||||
private def coursierProject0(
|
private def coursierProject0(
|
||||||
projId: ModuleID,
|
projId: ModuleID,
|
||||||
dependencies: Seq[ModuleID],
|
dependencies: Seq[ModuleID],
|
||||||
excludeDeps: Seq[InclExclRule],
|
|
||||||
configurations: Seq[sbt.librarymanagement.Configuration],
|
configurations: Seq[sbt.librarymanagement.Configuration],
|
||||||
sv: String,
|
sv: String,
|
||||||
sbv: String,
|
sbv: String,
|
||||||
log: Logger
|
log: Logger
|
||||||
): Project = {
|
): Project = {
|
||||||
|
|
||||||
val exclusions0 = Inputs.exclusions(excludeDeps, sv, sbv, log)
|
|
||||||
|
|
||||||
val configMap = Inputs.configExtendsSeq(configurations).toMap
|
val configMap = Inputs.configExtendsSeq(configurations).toMap
|
||||||
|
|
||||||
val proj = FromSbt.project(
|
FromSbt.project(
|
||||||
projId,
|
projId,
|
||||||
dependencies,
|
dependencies,
|
||||||
configMap,
|
configMap,
|
||||||
sv,
|
sv,
|
||||||
sbv
|
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]] =
|
private[sbtcoursiershared] def coursierProjectTask: Def.Initialize[sbt.Task[Project]] =
|
||||||
|
|
@ -68,7 +57,6 @@ object InputsTasks {
|
||||||
coursierProject0(
|
coursierProject0(
|
||||||
projectID.in(projectRef).get(state),
|
projectID.in(projectRef).get(state),
|
||||||
allDependenciesTask.value,
|
allDependenciesTask.value,
|
||||||
actualExcludeDependencies.in(projectRef).get(state),
|
|
||||||
// should projectID.configurations be used instead?
|
// should projectID.configurations be used instead?
|
||||||
ivyConfigurations.in(projectRef).get(state),
|
ivyConfigurations.in(projectRef).get(state),
|
||||||
scalaVersion.in(projectRef).get(state),
|
scalaVersion.in(projectRef).get(state),
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,16 @@ object ResolutionTasks {
|
||||||
.map(_.foldLeft[ProjectCache](Map.empty)(_ ++ _))
|
.map(_.foldLeft[ProjectCache](Map.empty)(_ ++ _))
|
||||||
.getOrElse(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
|
val mainRepositories = resolvers
|
||||||
.flatMap { resolver =>
|
.flatMap { resolver =>
|
||||||
Resolvers.repository(
|
Resolvers.repository(
|
||||||
|
|
@ -154,7 +164,8 @@ object ResolutionTasks {
|
||||||
.withProfiles(userEnabledProfiles)
|
.withProfiles(userEnabledProfiles)
|
||||||
.withForceVersion(userForceVersions.map { case (k, v) => (ToCoursier.module(k), v) }.toMap)
|
.withForceVersion(userForceVersions.map { case (k, v) => (ToCoursier.module(k), v) }.toMap)
|
||||||
.withTypelevel(typelevel)
|
.withTypelevel(typelevel)
|
||||||
.addReconciliation(versionReconciliations0: _*),
|
.addReconciliation(versionReconciliations0: _*)
|
||||||
|
.withExclusions(excludeDeps),
|
||||||
strictOpt = strictOpt,
|
strictOpt = strictOpt,
|
||||||
missingOk = missingOk,
|
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"
|
lazy val b = project
|
||||||
name := "sbt-coursier-exclude-dependencies"
|
.settings(
|
||||||
version := "0.1.0-SNAPSHOT"
|
organization := "io.get-coursier.test",
|
||||||
|
name := "sbt-coursier-exclude-dependencies-2",
|
||||||
libraryDependencies += "com.github.alexarchambault" %% "argonaut-shapeless_6.2" % "1.2.0-M11"
|
version := "0.1.0-SNAPSHOT",
|
||||||
|
scalaVersion := "2.12.8",
|
||||||
excludeDependencies += sbt.ExclusionRule("com.chuusai", "shapeless_2.12")
|
libraryDependencies ++= Seq(
|
||||||
excludeDependencies += "io.argonaut" %% "argonaut"
|
"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
|
> a/run
|
||||||
> publishLocal
|
> a/publishLocal
|
||||||
$ exec java -jar coursier launch io.get-coursier.test:sbt-coursier-exclude-dependencies_2.12:0.1.0-SNAPSHOT
|
$ 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