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, csrRecursiveResolvers := CoursierRepositoriesTasks.coursierRecursiveResolversTask.value,
csrSbtResolvers := CoursierRepositoriesTasks.coursierSbtResolversTask.value, csrSbtResolvers := CoursierRepositoriesTasks.coursierSbtResolversTask.value,
csrInterProjectDependencies := CoursierInputsTasks.coursierInterProjectDependenciesTask.value, csrInterProjectDependencies := CoursierInputsTasks.coursierInterProjectDependenciesTask.value,
csrExtraProjects := CoursierInputsTasks.coursierExtraProjectsTask.value,
csrFallbackDependencies := CoursierInputsTasks.coursierFallbackDependenciesTask.value, csrFallbackDependencies := CoursierInputsTasks.coursierFallbackDependenciesTask.value,
) ++ ) ++
IvyXml.generateIvyXmlSettings() ++ 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 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 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 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 csrFallbackDependencies = taskKey[Seq[FallbackDependency]]("")
val csrLogger = taskKey[Option[CacheLogger]]("") val csrLogger = taskKey[Option[CacheLogger]]("")
val csrExtraCredentials = taskKey[Seq[lmcoursier.credentials.Credentials]]("") val csrExtraCredentials = taskKey[Seq[lmcoursier.credentials.Credentials]]("")
val csrPublications = taskKey[Seq[(lmcoursier.definitions.Configuration, lmcoursier.definitions.Publication)]]("") val csrPublications = taskKey[Seq[(lmcoursier.definitions.Configuration, lmcoursier.definitions.Publication)]]("")
val csrReconciliations = settingKey[Seq[(ModuleMatchers, Reconciliation)]]("Strategy to reconcile version conflicts.") 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 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 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) 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]]] = private[sbt] def coursierInterProjectDependenciesTask: Def.Initialize[sbt.Task[Seq[CProject]]] =
Def.taskDyn { Def.taskDyn {
val state = sbt.Keys.state.value val state = sbt.Keys.state.value
val projectRef = sbt.Keys.thisProjectRef.value val projectRef = sbt.Keys.thisProjectRef.value
val projectRefs = Project.transitiveInterDependencies(state, projectRef) val projectRefs = Project.transitiveInterDependencies(state, projectRef)
Def.task { Def.task {
val projects = csrProject.all(ScopeFilter(inProjects(projectRefs: _*))).value csrProject.all(ScopeFilter(inProjects(projectRefs :+ projectRef: _*))).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
} }
} }
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 private[sbt] def coursierFallbackDependenciesTask
: Def.Initialize[sbt.Task[Seq[FallbackDependency]]] = : Def.Initialize[sbt.Task[Seq[FallbackDependency]]] =
Def.taskDyn { Def.taskDyn {

View File

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