mirror of https://github.com/sbt/sbt.git
Use parent's projects resolution result as project cache
This commit is contained in:
parent
34ff7662db
commit
f0d314d7f2
|
|
@ -54,6 +54,7 @@ package object coursier {
|
|||
|
||||
type ModuleVersion = (core.Module, String)
|
||||
|
||||
type ProjectCache = Map[ModuleVersion, (Artifact.Source, Project)]
|
||||
|
||||
type Repository = core.Repository
|
||||
val Repository = core.Repository
|
||||
|
|
@ -69,7 +70,7 @@ package object coursier {
|
|||
dependencies: Set[Dependency] = Set.empty,
|
||||
forceVersions: Map[Module, String] = Map.empty,
|
||||
conflicts: Set[Dependency] = Set.empty,
|
||||
projectCache: Map[ModuleVersion, (Artifact.Source, Project)] = Map.empty,
|
||||
projectCache: ProjectCache = Map.empty,
|
||||
errorCache: Map[ModuleVersion, Seq[String]] = Map.empty,
|
||||
finalDependencies: Map[Dependency, Seq[Dependency]] = Map.empty,
|
||||
filter: Option[Dependency => Boolean] = None,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ object CoursierPlugin extends AutoPlugin {
|
|||
|
||||
val coursierConfigurations = Keys.coursierConfigurations
|
||||
|
||||
val coursierParentProjectCache = Keys.coursierParentProjectCache
|
||||
val coursierResolution = Keys.coursierResolution
|
||||
val coursierSbtClassifiersResolution = Keys.coursierSbtClassifiersResolution
|
||||
|
||||
|
|
@ -118,6 +119,7 @@ object CoursierPlugin extends AutoPlugin {
|
|||
coursierPublications <<= Tasks.coursierPublicationsTask(packageConfigs: _*),
|
||||
coursierSbtClassifiersModule <<= classifiersModule in updateSbtClassifiers,
|
||||
coursierConfigurations <<= Tasks.coursierConfigurationsTask(None),
|
||||
coursierParentProjectCache <<= Tasks.parentProjectCacheTask,
|
||||
coursierResolution <<= Tasks.resolutionTask(),
|
||||
coursierSbtClassifiersResolution <<= Tasks.resolutionTask(
|
||||
sbtClassifiers = true
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ object Keys {
|
|||
|
||||
val coursierConfigurations = TaskKey[Map[String, Set[String]]]("coursier-configurations")
|
||||
|
||||
|
||||
val coursierParentProjectCache = TaskKey[Map[Seq[Resolver], Seq[ProjectCache]]]("coursier-parent-project-cache")
|
||||
val coursierResolution = TaskKey[Resolution]("coursier-resolution")
|
||||
val coursierSbtClassifiersResolution = TaskKey[Resolution]("coursier-sbt-classifiers-resolution")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +1,25 @@
|
|||
package coursier
|
||||
|
||||
import java.io.{ File, InputStream, OutputStreamWriter }
|
||||
import java.io.{File, InputStream, OutputStreamWriter}
|
||||
import java.net.URL
|
||||
import java.util.concurrent.{ ExecutorService, Executors }
|
||||
import java.util.concurrent.{ExecutorService, Executors}
|
||||
|
||||
import coursier.core.{ Authentication, Publication }
|
||||
import coursier.ivy.{ IvyRepository, PropertiesPattern }
|
||||
import coursier.core.{Authentication, Publication}
|
||||
import coursier.ivy.{IvyRepository, PropertiesPattern}
|
||||
import coursier.Keys._
|
||||
import coursier.Structure._
|
||||
import coursier.internal.FileUtil
|
||||
import coursier.util.{ Config, Print }
|
||||
import coursier.util.{Config, Print}
|
||||
import org.apache.ivy.core.module.id.ModuleRevisionId
|
||||
|
||||
import sbt.{ UpdateReport, Classpaths, Resolver, Def }
|
||||
import sbt.{ClasspathDep, Classpaths, Def, ProjectRef, Resolver, UpdateReport}
|
||||
import sbt.Keys._
|
||||
|
||||
import scala.collection.mutable
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
import scala.util.Try
|
||||
|
||||
import scalaz.{ \/-, -\/ }
|
||||
import scalaz.concurrent.{ Task, Strategy }
|
||||
import scalaz.{-\/, \/-}
|
||||
import scalaz.concurrent.{Strategy, Task}
|
||||
|
||||
object Tasks {
|
||||
|
||||
|
|
@ -317,6 +315,28 @@ object Tasks {
|
|||
}
|
||||
}
|
||||
|
||||
def parentProjectCacheTask: Def.Initialize[sbt.Task[Map[Seq[sbt.Resolver],Seq[coursier.ProjectCache]]]] =
|
||||
(sbt.Keys.state,
|
||||
sbt.Keys.thisProjectRef).flatMap{ (state, projectRef) =>
|
||||
|
||||
val projectDeps = structure(state).allProjects
|
||||
.find(_.id == projectRef.project)
|
||||
.map(_.dependencies.map(_.project.project).toSet)
|
||||
.getOrElse(Set.empty)
|
||||
|
||||
val projects = structure(state).allProjectRefs.filter(p => projectDeps(p.project))
|
||||
|
||||
coursierRecursiveResolvers.forAllProjects(state, projects).flatMap{ m =>
|
||||
coursierResolution.forAllProjects(state, m.keys.toSeq).map{ n =>
|
||||
n.foldLeft(Map.empty[Seq[Resolver], Seq[ProjectCache]]){ case (caches, (ref, resolution)) =>
|
||||
m.get(ref).fold(caches)(resolvers =>
|
||||
caches.updated(resolvers, resolution.projectCache +: caches.getOrElse(resolvers, Seq.empty)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def resolutionTask(
|
||||
sbtClassifiers: Boolean = false
|
||||
) = Def.task {
|
||||
|
|
@ -400,6 +420,11 @@ object Tasks {
|
|||
else
|
||||
coursierRecursiveResolvers.value.distinct
|
||||
|
||||
val parentProjectCache: ProjectCache = coursierParentProjectCache.value
|
||||
.get(resolvers)
|
||||
.map(_.foldLeft[ProjectCache](Map.empty)(_ ++ _))
|
||||
.getOrElse(Map.empty)
|
||||
|
||||
// TODO Warn about possible duplicated modules from source repositories?
|
||||
|
||||
val verbosityLevel = coursierVerbosity.value
|
||||
|
|
@ -421,7 +446,8 @@ object Tasks {
|
|||
// order matters here
|
||||
userForceVersions ++
|
||||
forcedScalaModules(so, sv) ++
|
||||
interProjectDependencies.map(_.moduleVersion)
|
||||
interProjectDependencies.map(_.moduleVersion),
|
||||
projectCache = parentProjectCache
|
||||
)
|
||||
|
||||
if (verbosityLevel >= 2) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue