Fix inter-project dependencies

Tracking https://github.com/coursier/sbt-coursier/pull/101
This commit is contained in:
Eugene Yokota 2019-08-09 22:55:10 -04:00
parent 46e92949ed
commit 777cc39fcf
4 changed files with 46 additions and 37 deletions

View File

@ -2458,6 +2458,7 @@ object Classpaths {
csrRecursiveResolvers := CoursierRepositoriesTasks.coursierRecursiveResolversTask.value,
csrSbtResolvers := CoursierRepositoriesTasks.coursierSbtResolversTask.value,
csrInterProjectDependencies := CoursierInputsTasks.coursierInterProjectDependenciesTask.value,
csrExtraProjects := CoursierInputsTasks.coursierExtraProjectsTask.value,
csrFallbackDependencies := CoursierInputsTasks.coursierFallbackDependenciesTask.value,
) ++
IvyXml.generateIvyXmlSettings() ++

View File

@ -335,12 +335,13 @@ object Keys {
val csrRecursiveResolvers = taskKey[Seq[Resolver]]("Resolvers of the current project, plus those of all from its inter-dependency projects")
val csrSbtResolvers = taskKey[Seq[Resolver]]("Resolvers used for sbt artifacts.")
val csrInterProjectDependencies = taskKey[Seq[lmcoursier.definitions.Project]]("Projects the current project depends on, possibly transitively")
val csrExtraProjects = taskKey[Seq[lmcoursier.definitions.Project]]("").withRank(CTask)
val csrFallbackDependencies = taskKey[Seq[FallbackDependency]]("")
val csrLogger = taskKey[Option[CacheLogger]]("")
val csrExtraCredentials = taskKey[Seq[lmcoursier.credentials.Credentials]]("")
val csrPublications = taskKey[Seq[(lmcoursier.definitions.Configuration, lmcoursier.definitions.Publication)]]("")
val csrReconciliations = settingKey[Seq[(ModuleMatchers, Reconciliation)]]("Strategy to reconcile version conflicts.")
val internalConfigurationMap = settingKey[Configuration => Configuration]("Maps configurations to the actual configuration used to define the classpath.").withRank(CSetting)
val classpathConfiguration = taskKey[Configuration]("The configuration used to define the classpath.").withRank(CTask)
val ivyConfiguration = taskKey[IvyConfiguration]("General dependency management (Ivy) settings, such as the resolvers and paths to use.").withRank(DTask)

View File

@ -142,49 +142,50 @@ object CoursierInputsTasks {
private[sbt] def coursierInterProjectDependenciesTask: Def.Initialize[sbt.Task[Seq[CProject]]] =
Def.taskDyn {
val state = sbt.Keys.state.value
val projectRef = sbt.Keys.thisProjectRef.value
val projectRefs = Project.transitiveInterDependencies(state, projectRef)
Def.task {
val projects = csrProject.all(ScopeFilter(inProjects(projectRefs: _*))).value
val projectModules = projects.map(_.module).toSet
// this includes org.scala-sbt:global-plugins referenced from meta-builds in particular
val extraProjects = sbt.Keys.projectDescriptors.value
.map {
case (k, v) =>
moduleFromIvy(k) -> v
}
.filter {
case (module, _) =>
!projectModules(module)
}
.toVector
.map {
case (module, v) =>
val configurations = v.getConfigurations.map { c =>
CConfiguration(c.getName) -> c.getExtends.map(CConfiguration(_)).toSeq
}.toMap
val deps = v.getDependencies.flatMap(dependencyFromIvy)
CProject(
module,
v.getModuleRevisionId.getRevision,
deps,
configurations,
Nil,
None,
Nil,
CInfo("", "", Nil, Nil, None)
)
}
projects ++ extraProjects
csrProject.all(ScopeFilter(inProjects(projectRefs :+ projectRef: _*))).value
}
}
private[sbt] def coursierExtraProjectsTask: Def.Initialize[sbt.Task[Seq[CProject]]] = {
Def.task {
val projects = csrInterProjectDependencies.value
val projectModules = projects.map(_.module).toSet
// this includes org.scala-sbt:global-plugins referenced from meta-builds in particular
sbt.Keys.projectDescriptors.value
.map {
case (k, v) =>
moduleFromIvy(k) -> v
}
.filter {
case (module, _) =>
!projectModules(module)
}
.toVector
.map {
case (module, v) =>
val configurations = v.getConfigurations.map { c =>
CConfiguration(c.getName) -> c.getExtends.map(CConfiguration(_)).toSeq
}.toMap
val deps = v.getDependencies.flatMap(dependencyFromIvy)
CProject(
module,
v.getModuleRevisionId.getRevision,
deps,
configurations,
Nil,
None,
Nil,
CInfo("", "", Nil, Nil, None)
)
}
}
}
private[sbt] def coursierFallbackDependenciesTask
: Def.Initialize[sbt.Task[Seq[FallbackDependency]]] =
Def.taskDyn {

View File

@ -48,6 +48,7 @@ object LMCoursier {
def coursierConfiguration(
rs: Seq[Resolver],
interProjectDependencies: Seq[CProject],
extraProjects: Seq[CProject],
fallbackDeps: Seq[FallbackDependency],
appConfig: AppConfiguration,
classifiers: Option[Seq[Classifier]],
@ -88,6 +89,7 @@ object LMCoursier {
CoursierConfiguration()
.withResolvers(rs.toVector)
.withInterProjectDependencies(interProjectDependencies.toVector)
.withExtraProjects(extraProjects.toVector)
.withFallbackDependencies(fallbackDeps.toVector)
.withExcludeDependencies(coursierExcludeDeps)
.withAutoScalaLibrary(autoScala)
@ -110,6 +112,7 @@ object LMCoursier {
coursierConfiguration(
csrRecursiveResolvers.value,
csrInterProjectDependencies.value.toVector,
csrExtraProjects.value.toVector,
csrFallbackDependencies.value,
appConfiguration.value,
None,
@ -132,6 +135,7 @@ object LMCoursier {
coursierConfiguration(
csrRecursiveResolvers.value,
csrInterProjectDependencies.value.toVector,
csrExtraProjects.value.toVector,
csrFallbackDependencies.value,
appConfiguration.value,
Some(transitiveClassifiers.value.map(Classifier(_))),
@ -154,6 +158,7 @@ object LMCoursier {
coursierConfiguration(
csrSbtResolvers.value,
Vector(),
Vector(),
csrFallbackDependencies.value,
appConfiguration.value,
None,
@ -176,6 +181,7 @@ object LMCoursier {
coursierConfiguration(
csrResolvers.value,
Vector(),
Vector(),
csrFallbackDependencies.value,
appConfiguration.value,
None,