Take dependencyOverrides into account in sbt-lm-coursier (#106)

This commit is contained in:
Alexandre Archambault 2019-07-23 20:26:00 +02:00 committed by GitHub
parent 0400b537f4
commit e39b9cf55c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 22 deletions

View File

@ -8,7 +8,7 @@ package lmcoursier
import java.io.File
import lmcoursier.credentials.Credentials
import lmcoursier.definitions.{Authentication, CacheLogger, Project, Strict}
import lmcoursier.definitions.{Authentication, CacheLogger, Module, Project, Strict}
import sbt.librarymanagement.Resolver
import xsbti.Logger
@ -36,7 +36,8 @@ final class CoursierConfiguration private (
val ivyHome: Option[File],
val followHttpToHttpsRedirections: Option[Boolean],
val strict: Option[Strict],
val extraProjects: Vector[Project]
val extraProjects: Vector[Project],
val forceVersions: Vector[(Module, String)]
) extends Serializable {
private def this() =
@ -64,6 +65,7 @@ final class CoursierConfiguration private (
None,
None,
None,
Vector.empty,
Vector.empty
)
@ -115,6 +117,7 @@ final class CoursierConfiguration private (
ivyHome,
followHttpToHttpsRedirections,
None,
Vector.empty,
Vector.empty
)
@ -144,7 +147,8 @@ final class CoursierConfiguration private (
ivyHome == other.ivyHome &&
followHttpToHttpsRedirections == other.followHttpToHttpsRedirections &&
strict == other.strict &&
extraProjects == other.extraProjects
extraProjects == other.extraProjects &&
forceVersions == other.forceVersions
case _ => false
}
@ -174,11 +178,12 @@ final class CoursierConfiguration private (
code = 37 * (code + followHttpToHttpsRedirections.##)
code = 37 * (code + strict.##)
code = 37 * (code + extraProjects.##)
code = 37 * (code + forceVersions.##)
code
}
override def toString: String =
s"CoursierConfiguration($log, $resolvers, $parallelDownloads, $maxIterations, $sbtScalaOrganization, $sbtScalaVersion, $sbtScalaJars, $interProjectDependencies, $excludeDependencies, $fallbackDependencies, $autoScalaLibrary, $hasClassifiers, $classifiers, $mavenProfiles, $scalaOrganization, $scalaVersion, $authenticationByRepositoryId, $credentials, $logger, $cache, $ivyHome, $followHttpToHttpsRedirections, $strict, $extraProjects)"
s"CoursierConfiguration($log, $resolvers, $parallelDownloads, $maxIterations, $sbtScalaOrganization, $sbtScalaVersion, $sbtScalaJars, $interProjectDependencies, $excludeDependencies, $fallbackDependencies, $autoScalaLibrary, $hasClassifiers, $classifiers, $mavenProfiles, $scalaOrganization, $scalaVersion, $authenticationByRepositoryId, $credentials, $logger, $cache, $ivyHome, $followHttpToHttpsRedirections, $strict, $extraProjects, $forceVersions)"
private[this] def copy(
log: Option[Logger] = log,
@ -204,7 +209,8 @@ final class CoursierConfiguration private (
ivyHome: Option[File] = ivyHome,
followHttpToHttpsRedirections: Option[Boolean] = followHttpToHttpsRedirections,
strict: Option[Strict] = strict,
extraProjects: Vector[Project] = extraProjects
extraProjects: Vector[Project] = extraProjects,
forceVersions: Vector[(Module, String)] = forceVersions
): CoursierConfiguration =
new CoursierConfiguration(
log,
@ -230,7 +236,8 @@ final class CoursierConfiguration private (
ivyHome,
followHttpToHttpsRedirections,
strict,
extraProjects
extraProjects,
forceVersions
)
def withLog(log: Option[Logger]): CoursierConfiguration =
@ -333,6 +340,9 @@ final class CoursierConfiguration private (
def withExtraProjects(extraProjects: Vector[Project]): CoursierConfiguration =
copy(extraProjects = extraProjects)
def withForceVersions(forceVersions: Vector[(Module, String)]): CoursierConfiguration =
copy(forceVersions = forceVersions)
}
object CoursierConfiguration {
@ -386,6 +396,7 @@ object CoursierConfiguration {
None,
None,
None,
Vector.empty,
Vector.empty
)
@ -435,6 +446,7 @@ object CoursierConfiguration {
None,
None,
None,
Vector.empty,
Vector.empty
)
@ -485,6 +497,7 @@ object CoursierConfiguration {
ivyHome,
None,
None,
Vector.empty,
Vector.empty
)
}

View File

@ -157,7 +157,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
params = coursier.params.ResolutionParams()
.withMaxIterations(conf.maxIterations)
.withProfiles(conf.mavenProfiles.toSet)
.withForceVersion(Map.empty)
.withForceVersion(conf.forceVersions.map { case (k, v) => (ToCoursier.module(k), v) }.toMap)
.withTypelevel(typelevel),
strictOpt = conf.strict.map(ToCoursier.strict)
)

View File

@ -1,8 +1,8 @@
package lmcoursier
import coursier.ivy.IvyXml.{mappings => initialIvyXmlMappings}
import lmcoursier.definitions.{Configuration, ModuleName, Organization}
import sbt.librarymanagement.{CrossVersion, InclExclRule}
import lmcoursier.definitions.{Configuration, Module, ModuleName, Organization, ToCoursier}
import sbt.librarymanagement.{CrossVersion, InclExclRule, ModuleID}
import sbt.util.Logger
import scala.collection.mutable
@ -124,4 +124,7 @@ object Inputs {
res
}
def forceVersions(depOverrides: Seq[ModuleID], sv: String, sbv: String): Seq[(Module, String)] =
depOverrides.map(FromSbt.moduleVersion(_, sv, sbv))
}

View File

@ -4,15 +4,14 @@ import coursier.ProjectCache
import coursier.cache.FileCache
import coursier.core._
import coursier.internal.Typelevel
import lmcoursier.definitions.{Strict, ToCoursier}
import lmcoursier.{FallbackDependency, FromSbt}
import lmcoursier.definitions.ToCoursier
import lmcoursier.{FallbackDependency, FromSbt, Inputs}
import lmcoursier.internal.{InterProjectRepository, ResolutionParams, ResolutionRun, Resolvers}
import coursier.sbtcoursier.Keys._
import coursier.sbtcoursiershared.InputsTasks.{credentialsTask, strictTask}
import coursier.sbtcoursiershared.SbtCoursierShared.autoImport._
import sbt.Def
import sbt.Keys._
import sbt.librarymanagement.ConflictManager
object ResolutionTasks {
@ -71,14 +70,7 @@ object ResolutionTasks {
// are these always defined? (e.g. for Java only projects?)
val so = Organization(scalaOrganization.value)
val userForceVersions = dependencyOverrides
.value
.map(FromSbt.moduleVersion(_, sv, sbv))
.map {
case (k, v) =>
ToCoursier.module(k) -> v
}
.toMap
val userForceVersions = Inputs.forceVersions(dependencyOverrides.value, sv, sbv)
val verbosityLevel = coursierVerbosity.value
@ -148,7 +140,7 @@ object ResolutionTasks {
params = coursier.params.ResolutionParams()
.withMaxIterations(maxIterations)
.withProfiles(userEnabledProfiles)
.withForceVersion(userForceVersions)
.withForceVersion(userForceVersions.map { case (k, v) => (ToCoursier.module(k), v) }.toMap)
.withTypelevel(typelevel),
strictOpt = strictOpt
),

View File

@ -0,0 +1,3 @@
scalaVersion := "2.12.8"
libraryDependencies += "io.get-coursier" %% "coursier" % "2.0.0-RC2-6"
dependencyOverrides += "io.get-coursier" %% "coursier-core" % "1.1.0-M14-7"

View File

@ -0,0 +1,13 @@
addSbtPlugin {
val name = sys.props.getOrElse(
"plugin.name",
sys.error("plugin.name Java property not set")
)
val version = sys.props.getOrElse(
"plugin.version",
sys.error("plugin.version Java property not set")
)
"io.get-coursier" % name % version
}

View File

@ -0,0 +1,9 @@
import coursier.util.Properties
object Main extends App {
val expected = "1.1.0-M14-7"
assert(
Properties.version == expected,
s"Expected coursier-core $expected, got ${Properties.version}"
)
}

View File

@ -0,0 +1 @@
> run

View File

@ -7,7 +7,7 @@ import coursier.sbtcoursiershared.{InputsTasks, SbtCoursierShared}
import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey}
import sbt.Project.inTask
import sbt.KeyRanks.DTask
import sbt.Keys.{appConfiguration, autoScalaLibrary, classpathTypes, dependencyResolution, ivyPaths, scalaBinaryVersion, scalaModuleInfo, scalaOrganization, scalaVersion, streams, updateClassifiers, updateSbtClassifiers}
import sbt.Keys.{appConfiguration, autoScalaLibrary, classpathTypes, dependencyOverrides, dependencyResolution, ivyPaths, scalaBinaryVersion, scalaModuleInfo, scalaOrganization, scalaVersion, streams, updateClassifiers, updateSbtClassifiers}
import sbt.librarymanagement.DependencyResolution
import scala.language.reflectiveCalls
@ -83,6 +83,7 @@ object LmCoursierPlugin extends AutoPlugin {
val rs = resolversTask.value
val scalaOrg = scalaOrganization.value
val scalaVer = scalaVersion.value
val sbv = scalaBinaryVersion.value
val interProjectDependencies = interProjectDependenciesTask.value
val extraProjects = coursierExtraProjects.value
val excludeDeps = Inputs.exclusions(
@ -95,6 +96,9 @@ object LmCoursierPlugin extends AutoPlugin {
val autoScalaLib = autoScalaLibrary.value && scalaModuleInfo.value.forall(_.overrideScalaVersion)
val profiles = mavenProfiles.value
val userForceVersions = Inputs.forceVersions(dependencyOverrides.value, scalaVer, sbv)
val authenticationByRepositoryId = coursierCredentials.value.mapValues { c =>
val a = c.authentication
Authentication(a.user, a.password, a.optional, a.realmOpt)
@ -143,6 +147,7 @@ object LmCoursierPlugin extends AutoPlugin {
.withLog(s.log)
.withIvyHome(ivyPaths.value.ivyHome)
.withStrict(strict)
.withForceVersions(userForceVersions.toVector)
}
}
private def mkDependencyResolution: Def.Initialize[Task[DependencyResolution]] =