Skip to content

Remove CoursierModule#mapDependencies #5070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions core/util/src/mill/util/Jvm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ object Jvm {
force: IterableOnce[Dependency] = Nil,
checkGradleModules: Boolean,
sources: Boolean = false,
mapDependencies: Option[Dependency => Dependency] = None,
customizer: Option[Resolution => Resolution] = None,
ctx: Option[mill.define.TaskCtx] = None,
coursierCacheCustomizer: Option[FileCache[Task] => FileCache[Task]] = None,
Expand All @@ -478,7 +477,6 @@ object Jvm {
deps,
force,
checkGradleModules,
mapDependencies,
customizer,
ctx,
coursierCacheCustomizer,
Expand Down Expand Up @@ -529,7 +527,6 @@ object Jvm {
force: IterableOnce[Dependency],
checkGradleModules: Boolean,
sources: Boolean = false,
mapDependencies: Option[Dependency => Dependency] = None,
customizer: Option[Resolution => Resolution] = None,
ctx: Option[mill.define.TaskCtx] = None,
coursierCacheCustomizer: Option[FileCache[Task] => FileCache[Task]] = None,
Expand All @@ -542,7 +539,6 @@ object Jvm {
force,
checkGradleModules,
sources,
mapDependencies,
customizer,
ctx,
coursierCacheCustomizer,
Expand Down Expand Up @@ -630,20 +626,16 @@ object Jvm {
deps: IterableOnce[Dependency],
force: IterableOnce[Dependency],
checkGradleModules: Boolean,
mapDependencies: Option[Dependency => Dependency] = None,
customizer: Option[Resolution => Resolution] = None,
ctx: Option[mill.define.TaskCtx] = None,
coursierCacheCustomizer: Option[FileCache[Task] => FileCache[Task]] = None,
resolutionParams: ResolutionParams = ResolutionParams(),
boms: IterableOnce[BomDependency] = Nil
): Result[Resolution] = {

val rootDeps = deps.iterator
.map(d => mapDependencies.fold(d)(_.apply(d)))
.toSeq
val rootDeps = deps.iterator.toSeq

val forceVersions = force.iterator
.map(mapDependencies.getOrElse(identity[Dependency](_)))
.map { d => d.module -> d.version }
.toMap

Expand Down Expand Up @@ -682,7 +674,6 @@ object Jvm {
.withDependencies(rootDeps)
.withRepositories(Seq(resourceTestOverridesRepo) ++ envTestOverridesRepo ++ repositories0)
.withResolutionParams(resolutionParams0)
.withMapDependenciesOpt(mapDependencies)
.withBoms(boms.iterator.toSeq)

resolve.either() match {
Expand Down
14 changes: 1 addition & 13 deletions libs/scalalib/src/mill/scalalib/CoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ trait CoursierModule extends mill.define.Module {
new CoursierModule.Resolver(
repositories = allRepositories(),
bind = bindDependency(),
mapDependencies = Some(mapDependencies()),
customizer = resolutionCustomizer(),
coursierCacheCustomizer = coursierCacheCustomizer(),
resolutionParams = resolutionParams(),
Expand All @@ -68,7 +67,6 @@ trait CoursierModule extends mill.define.Module {
new CoursierModule.Resolver(
repositories = repositoriesTask(),
bind = bindDependency(),
mapDependencies = Some(mapDependencies()),
customizer = resolutionCustomizer(),
coursierCacheCustomizer = coursierCacheCustomizer(),
resolutionParams = resolutionParams(),
Expand All @@ -77,12 +75,6 @@ trait CoursierModule extends mill.define.Module {
)
}

/**
* Map dependencies before resolving them.
* Override this to customize the set of dependencies.
*/
def mapDependencies: Task[Dependency => Dependency] = Task.Anon { (d: Dependency) => d }

/**
* Mill internal repositories to be used during dependency resolution
*
Expand Down Expand Up @@ -203,7 +195,6 @@ object CoursierModule {
repositories: Seq[Repository],
bind: Dep => BoundDep,
checkGradleModules: Boolean,
mapDependencies: Option[Dependency => Dependency] = None,
customizer: Option[coursier.core.Resolution => coursier.core.Resolution] = None,
coursierCacheCustomizer: Option[
coursier.cache.FileCache[coursier.util.Task] => coursier.cache.FileCache[coursier.util.Task]
Expand All @@ -222,16 +213,14 @@ object CoursierModule {
deps: IterableOnce[T],
sources: Boolean = false,
artifactTypes: Option[Set[coursier.Type]] = None,
resolutionParamsMapOpt: Option[ResolutionParams => ResolutionParams] = None,
mapDependencies: Option[Dependency => Dependency] = null
resolutionParamsMapOpt: Option[ResolutionParams => ResolutionParams] = None
)(implicit ctx: mill.define.TaskCtx): Seq[PathRef] =
Lib.resolveDependencies(
repositories = repositories,
deps = deps.iterator.map(implicitly[CoursierModule.Resolvable[T]].bind(_, bind)),
checkGradleModules = checkGradleModules,
sources = sources,
artifactTypes = artifactTypes,
mapDependencies = Option(mapDependencies).getOrElse(this.mapDependencies),
customizer = customizer,
coursierCacheCustomizer = coursierCacheCustomizer,
ctx = Some(ctx),
Expand All @@ -254,7 +243,6 @@ object CoursierModule {
repositories = repositories,
deps = deps0,
checkGradleModules = checkGradleModules,
mapDependencies = mapDependencies,
customizer = customizer,
coursierCacheCustomizer = coursierCacheCustomizer,
ctx = Some(ctx),
Expand Down
1 change: 0 additions & 1 deletion libs/scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,6 @@ trait JavaModule
allRepositories(),
dependencies,
checkGradleModules = checkGradleModules(),
Some(mapDependencies()),
customizer = resolutionCustomizer(),
coursierCacheCustomizer = coursierCacheCustomizer(),
resolutionParams = resolutionParams()
Expand Down
22 changes: 14 additions & 8 deletions libs/scalalib/src/mill/scalalib/JvmWorkerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ trait JvmWorkerModule extends OfflineSupportModule with CoursierModule {
val deps = resolver.classpath(
Seq(bridgeDep.bindDep("", "", "")),
sources = useSources,
mapDependencies = Some(overrideScalaLibrary(scalaVersion, scalaOrganization))
resolutionParamsMapOpt = Some(overrideScalaLibrary(scalaVersion, scalaOrganization))
)

val bridgeJar = JvmWorkerUtil.grepJar(deps, bridgeName, bridgeVersion, useSources)
Expand All @@ -173,19 +173,25 @@ trait JvmWorkerModule extends OfflineSupportModule with CoursierModule {
deps = Seq(mvn"org.scala-sbt:compiler-interface:${Versions.zinc}".bindDep("", "", "")),
// Since Zinc 1.4.0, the compiler-interface depends on the Scala library
// We need to override it with the scalaVersion and scalaOrganization of the module
mapDependencies = Some(overrideScalaLibrary(scalaVersion, scalaOrganization))
resolutionParamsMapOpt = Some(overrideScalaLibrary(scalaVersion, scalaOrganization))
)
}

def overrideScalaLibrary(
scalaVersion: String,
scalaOrganization: String
)(dep: coursier.Dependency): coursier.Dependency = {
if (dep.module.name.value == "scala-library") {
dep.withModule(dep.module.withOrganization(coursier.Organization(scalaOrganization)))
.withVersion(scalaVersion)
} else dep
}
): coursier.params.ResolutionParams => coursier.params.ResolutionParams =
params =>
params
.withTypelevel(scalaOrganization == "org.typelevel")
.addForceVersion0(
coursier.Module(
coursier.Organization(scalaOrganization),
coursier.ModuleName("scala-library"),
Map.empty
) ->
coursier.version.VersionConstraint(scalaVersion)
)

override def prepareOffline(all: Flag): Command[Seq[PathRef]] = Task.Command {
(
Expand Down
4 changes: 0 additions & 4 deletions libs/scalalib/src/mill/scalalib/Lib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ object Lib {
repositories: Seq[Repository],
deps: IterableOnce[BoundDep],
checkGradleModules: Boolean,
mapDependencies: Option[Dependency => Dependency] = None,
customizer: Option[coursier.core.Resolution => coursier.core.Resolution] = None,
ctx: Option[TaskCtx] = None,
coursierCacheCustomizer: Option[
Expand All @@ -44,7 +43,6 @@ object Lib {
deps = depSeq.map(_.dep),
force = depSeq.filter(_.force).map(_.dep),
checkGradleModules = checkGradleModules,
mapDependencies = mapDependencies,
customizer = customizer,
ctx = ctx,
coursierCacheCustomizer = coursierCacheCustomizer,
Expand All @@ -65,7 +63,6 @@ object Lib {
deps: IterableOnce[BoundDep],
checkGradleModules: Boolean,
sources: Boolean = false,
mapDependencies: Option[Dependency => Dependency] = None,
customizer: Option[coursier.core.Resolution => coursier.core.Resolution] = None,
ctx: Option[TaskCtx] = None,
coursierCacheCustomizer: Option[
Expand All @@ -82,7 +79,6 @@ object Lib {
checkGradleModules = checkGradleModules,
sources = sources,
artifactTypes = artifactTypes,
mapDependencies = mapDependencies,
customizer = customizer,
ctx = ctx,
coursierCacheCustomizer = coursierCacheCustomizer,
Expand Down
35 changes: 19 additions & 16 deletions libs/scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,27 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase
*/
def scalaVersion: T[String]

override def mapDependencies: Task[coursier.Dependency => coursier.Dependency] = Task.Anon {
super.mapDependencies().andThen { (d: coursier.Dependency) =>
val artifacts =
if (JvmWorkerUtil.isDotty(scalaVersion()))
Set("dotty-library", "dotty-compiler")
else if (JvmWorkerUtil.isScala3(scalaVersion()))
Set("scala3-library", "scala3-compiler")
else
Set("scala-library", "scala-compiler", "scala-reflect")
if (!artifacts(d.module.name.value)) d
override def resolutionParams: Task[coursier.params.ResolutionParams] = Task.Anon {
val isTypelevelScala = scalaOrganization() == "org.typelevel"
val scalaModuleNames =
if (JvmWorkerUtil.isDotty(scalaVersion()))
Seq("dotty-library", "dotty-compiler")
else if (JvmWorkerUtil.isScala3(scalaVersion()))
Seq("scala3-library", "scala3-compiler")
else
d.withModule(
d.module.withOrganization(
coursier.Organization(scalaOrganization())
)
)
.withVersion(scalaVersion())
Seq("scala-library", "scala-compiler", "scala-reflect")
val constraint = coursier.version.VersionConstraint(scalaVersion())
val forced = scalaModuleNames.map { name =>
val mod = coursier.core.Module(
coursier.core.Organization(scalaOrganization()),
coursier.core.ModuleName(name),
Map.empty
)
(mod, constraint)
}
super.resolutionParams()
.withTypelevel(isTypelevelScala)
.addForceVersion0(forced*)
}

def bindDependency: Task[Dep => BoundDep] = Task.Anon { (dep: Dep) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ private[dependency] object VersionsFinder {
val compileMvnDeps = javaModule.compileMvnDeps()
val runMvnDeps = javaModule.runMvnDeps()
val repos = javaModule.repositoriesTask()
val mapDeps = javaModule.mapDependencies()
val custom = javaModule.resolutionCustomizer()
val cacheCustom = javaModule.coursierCacheCustomizer()

Expand All @@ -70,7 +69,6 @@ private[dependency] object VersionsFinder {
val x = Lib.resolveDependenciesMetadataSafe(
repositories = repos,
deps = dependencies: IterableOnce[BoundDep],
mapDependencies = Option(mapDeps),
customizer = custom,
ctx = Option(Task.ctx()),
coursierCacheCustomizer = cacheCustom,
Expand Down
22 changes: 5 additions & 17 deletions mill-build/src/millbuild/MillJavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,12 @@ trait MillJavaModule extends JavaModule {
Seq(MavenRepository("https://oss.sonatype.org/content/repositories/releases"))
}

def mapDependencies: Task[coursier.Dependency => coursier.Dependency] = Task.Anon {
super.mapDependencies().andThen { dep =>
forcedVersions.find(f =>
f.dep.module.organization.value == dep.module.organization.value &&
f.dep.module.name.value == dep.module.name.value
).map { forced =>
val newDep = dep.withVersionConstraint(VersionConstraint(forced.version))
Task.log.debug(
s"Forcing version of ${dep.module} from ${dep.versionConstraint.asString} to ${newDep.versionConstraint.asString}"
)
newDep
}.getOrElse(dep)
}
def resolutionParams: Task[coursier.params.ResolutionParams] = Task.Anon {
super.resolutionParams().addForceVersion0(
Deps.jline.dep.module -> Deps.jline.dep.versionConstraint,
Deps.jna.dep.module -> Deps.jna.dep.versionConstraint
)
}
val forcedVersions: Seq[Dep] = Deps.transitiveDeps ++ Seq(
Deps.jline,
Deps.jna
)

def javadocOptions = super.javadocOptions() ++ Seq(
// Disable warnings for missing documentation comments or tags (for example,
Expand Down