[2.x] feat: Add csrLocalArtifactsShouldBeCached setting for caching local artifacts (#8504)

This adds a new setting  that allows users to
configure Coursier's FileCache to cache local file:// artifacts. When enabled,
artifacts from local repositories are copied to the cache directory, which is
useful for scenarios like bundling compiler artifacts in a local repo for
offline use.

Fixes #7547
This commit is contained in:
MkDev11 2026-01-12 19:17:55 -05:00 committed by GitHub
parent 56c86a1684
commit 81b6408f49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 21 additions and 1 deletions

View File

@ -717,6 +717,7 @@ lazy val mainProj = (project in file("main"))
mimaSettings,
mimaBinaryIssueFilters ++= Vector(
exclude[DirectMissingMethodProblem]("sbt.internal.ConsoleProject.*"),
exclude[DirectMissingMethodProblem]("sbt.coursierint.LMCoursier.coursierConfiguration"),
),
)
.dependsOn(lmCore, lmIvy, lmCoursierShadedPublishing)

View File

@ -69,4 +69,6 @@ import scala.concurrent.duration.{ Duration, FiniteDuration }
protocolHandlerDependencies: Seq[ModuleID] = Vector.empty,
retry: Option[(FiniteDuration, Int)] = None,
sameVersions: Seq[Set[InclExclRule]] = Nil,
@since
localArtifactsShouldBeCached: Boolean = false,
)

View File

@ -240,6 +240,7 @@ class CoursierDependencyResolution(
.withChecksums(checksums)
.withCredentials(conf.credentials.map(ToCoursier.credentials))
.withFollowHttpToHttpsRedirections(conf.followHttpToHttpsRedirections.getOrElse(true))
.withLocalArtifactsShouldBeCached(conf.localArtifactsShouldBeCached)
val excludeDependencies = conf.excludeDependencies.map { (strOrg, strName) =>
(coursier.Organization(strOrg), coursier.ModuleName(strName))

View File

@ -77,6 +77,7 @@ package object syntax {
protocolHandlerDependencies = Vector.empty,
retry = None,
sameVersions = Nil,
localArtifactsShouldBeCached = false,
)
}

View File

@ -287,6 +287,7 @@ object Defaults extends BuildCommon {
csrMavenProfiles :== Set.empty,
csrReconciliations :== LMCoursier.relaxedForAllModules,
csrMavenDependencyOverride :== false,
csrLocalArtifactsShouldBeCached :== false,
csrCacheDirectory := LMCoursier.defaultCacheLocation,
csrSameVersions :== Nil,
stagingDirectory := (ThisBuild / baseDirectory).value / "target" / "sona-staging",

View File

@ -494,6 +494,8 @@ object Keys {
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 csrMavenDependencyOverride = settingKey[Boolean]("Enables Maven dependency override (bill of materials) support")
val csrLocalArtifactsShouldBeCached =
settingKey[Boolean]("When true, local file:// artifacts are copied to the cache directory.")
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)

View File

@ -92,6 +92,7 @@ object LMCoursier {
updateConfig: Option[UpdateConfiguration],
sameVersions: Seq[Set[InclExclRule]],
enableDependencyOverrides: Option[Boolean],
localArtifactsShouldBeCached: Boolean,
log: Logger
): CoursierConfiguration = {
val coursierExcludeDeps = Inputs
@ -143,7 +144,7 @@ object LMCoursier {
.withForceVersions(userForceVersions.toVector)
.withMissingOk(missingOk)
.withSameVersions(sameVersions)
// .withEnableDependencyOverrides(enableDependencyOverrides)
.withLocalArtifactsShouldBeCached(localArtifactsShouldBeCached)
}
def coursierConfigurationTask: Def.Initialize[Task[CoursierConfiguration]] = Def.task {
@ -171,6 +172,7 @@ object LMCoursier {
Some(updateConfiguration.value),
csrSameVersions.value,
Some(csrMavenDependencyOverride.value),
csrLocalArtifactsShouldBeCached.value,
streams.value.log
)
}
@ -207,6 +209,7 @@ object LMCoursier {
Some(updateConfiguration.value),
csrSameVersions.value,
Some(csrMavenDependencyOverride.value),
csrLocalArtifactsShouldBeCached.value,
streams.value.log
)
}
@ -236,6 +239,7 @@ object LMCoursier {
Some(updateConfiguration.value),
csrSameVersions.value,
Some(csrMavenDependencyOverride.value),
csrLocalArtifactsShouldBeCached.value,
streams.value.log
)
}

View File

@ -0,0 +1,7 @@
ThisBuild / scalaVersion := "2.13.16"
lazy val root = (project in file("."))
.settings(
name := "local-artifacts-cache-test",
csrLocalArtifactsShouldBeCached := true,
)

View File

@ -0,0 +1 @@
> show csrLocalArtifactsShouldBeCached