From 951d1c4ae4477c0f5fa94786c8474011e2977858 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Mon, 22 Jan 2024 16:44:09 +0100 Subject: [PATCH] Add new `csrSameVersions` setting, use it for Scala artifacts The `csrSameVersions` setting can be used to keep dependencies at the same version. By default it's used for Scala artifacts. They need to be kept at the same version because the compiler / reflect are built with cross-artifact inlining enabled. `csrSameVersions := Seq(Set(scala-library, scala-reflect, scala-compiler, scalap))` Users can make use of the new setting in the following way: - `csrSameVersions += Set[InclExclRule]("com.corp" % "lib", "com.corp" % "lub")` - `csrSameVersions += Set[InclExclRule]("com.corp" % "lib-family-*")` --- main/src/main/scala/sbt/Defaults.scala | 3 + main/src/main/scala/sbt/Keys.scala | 1 + .../scala/sbt/coursierint/LMCoursier.scala | 59 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index c9b00f748..ed83474dc 100644 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -271,6 +271,9 @@ object Defaults extends BuildCommon { csrLogger := LMCoursier.coursierLoggerTask.value, csrMavenProfiles :== Set.empty, csrReconciliations :== LMCoursier.relaxedForAllModules, + csrSameVersions := Seq( + ScalaArtifacts.Artifacts.map(a => InclExclRule(scalaOrganization.value, a)).toSet + ) ) /** Core non-plugin settings for sbt builds. These *must* be on every build or the sbt engine will fail to run at all. */ diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index 4d19d798d..69073fc16 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -452,6 +452,7 @@ object Keys { 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 csrSameVersions = settingKey[Seq[Set[InclExclRule]]]("Modules to keep at the same version.") 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) diff --git a/main/src/main/scala/sbt/coursierint/LMCoursier.scala b/main/src/main/scala/sbt/coursierint/LMCoursier.scala index 8d795072a..84ed5339d 100644 --- a/main/src/main/scala/sbt/coursierint/LMCoursier.scala +++ b/main/src/main/scala/sbt/coursierint/LMCoursier.scala @@ -74,6 +74,7 @@ object LMCoursier { def relaxedForAllModules: Seq[(ModuleMatchers, Reconciliation)] = Vector((ModuleMatchers.all, Reconciliation.Relaxed)) + // For binary compatibility / MiMa def coursierConfiguration( rs: Seq[Resolver], interProjectDependencies: Seq[CProject], @@ -119,6 +120,58 @@ object LMCoursier { strict, depsOverrides, None, + Nil, + log + ) + + // For binary compatibility / MiMa + def coursierConfiguration( + rs: Seq[Resolver], + interProjectDependencies: Seq[CProject], + extraProjects: Seq[CProject], + fallbackDeps: Seq[FallbackDependency], + appConfig: AppConfiguration, + classifiers: Option[Seq[Classifier]], + profiles: Set[String], + scalaOrg: String, + scalaVer: String, + scalaBinaryVer: String, + autoScalaLib: Boolean, + scalaModInfo: Option[ScalaModuleInfo], + excludeDeps: Seq[InclExclRule], + credentials: Seq[Credentials], + createLogger: Option[CacheLogger], + cacheDirectory: File, + reconciliation: Seq[(ModuleMatchers, Reconciliation)], + ivyHome: Option[File], + strict: Option[CStrict], + depsOverrides: Seq[ModuleID], + updateConfig: Option[UpdateConfiguration], + log: Logger + ): CoursierConfiguration = + coursierConfiguration( + rs, + interProjectDependencies, + extraProjects, + fallbackDeps, + appConfig, + classifiers, + profiles, + scalaOrg, + scalaVer, + scalaBinaryVer, + autoScalaLib, + scalaModInfo, + excludeDeps, + credentials, + createLogger, + cacheDirectory, + reconciliation, + ivyHome, + strict, + depsOverrides, + updateConfig, + Nil, log ) @@ -144,6 +197,7 @@ object LMCoursier { strict: Option[CStrict], depsOverrides: Seq[ModuleID], updateConfig: Option[UpdateConfiguration], + sameVersions: Seq[Set[InclExclRule]], log: Logger ): CoursierConfiguration = { val coursierExcludeDeps = Inputs @@ -197,6 +251,7 @@ object LMCoursier { .withStrict(strict) .withForceVersions(userForceVersions.toVector) .withMissingOk(missingOk) + .withSameVersions(sameVersions) } def coursierConfigurationTask: Def.Initialize[Task[CoursierConfiguration]] = Def.task { @@ -223,6 +278,7 @@ object LMCoursier { CoursierInputsTasks.strictTask.value, dependencyOverrides.value, Some(updateConfiguration.value), + csrSameVersions.value, streams.value.log ) } @@ -251,6 +307,7 @@ object LMCoursier { CoursierInputsTasks.strictTask.value, dependencyOverrides.value, Some(updateConfiguration.value), + csrSameVersions.value, streams.value.log ) } @@ -279,6 +336,7 @@ object LMCoursier { CoursierInputsTasks.strictTask.value, dependencyOverrides.value, Some(updateConfiguration.value), + csrSameVersions.value, streams.value.log ) } @@ -307,6 +365,7 @@ object LMCoursier { CoursierInputsTasks.strictTask.value, dependencyOverrides.value, Some(updateConfiguration.value), + csrSameVersions.value, streams.value.log ) }