Skip to content
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

Add BOM / dependency management support #3924

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
910e8a4
Remove trailing space
alexarchambault Nov 8, 2024
4f5f070
NIT Use allIvyDeps task
alexarchambault Nov 8, 2024
3e8643d
WIP Add BOM support
alexarchambault Nov 8, 2024
f796d0c
Merge branch 'main' into pr/bom-support
alexarchambault Nov 13, 2024
bc5e1b3
more
alexarchambault Nov 13, 2024
425b4aa
Merge branch 'main' into pr/bom-support
alexarchambault Nov 19, 2024
732c659
more
alexarchambault Nov 19, 2024
17259c0
fixup
alexarchambault Nov 19, 2024
a8b86e3
more
alexarchambault Nov 19, 2024
67ff17a
Merge branch 'main' into pr/bom-support
alexarchambault Nov 20, 2024
067d84d
more
alexarchambault Nov 20, 2024
17c3084
more
alexarchambault Nov 21, 2024
c143182
Merge branch 'main' into pr/bom-support
alexarchambault Nov 21, 2024
a45ddd6
fix
alexarchambault Nov 21, 2024
d601c44
Revert UnidocModule stuff
alexarchambault Nov 21, 2024
20f59c5
Merge branch 'main' into pr/bom-support
alexarchambault Nov 21, 2024
8c00ccb
Merge branch 'main' into pr/bom-support
alexarchambault Nov 21, 2024
f53fd8d
tweaking
alexarchambault Nov 21, 2024
c549b21
alexarchambault Nov 21, 2024
06b0c5b
more
alexarchambault Nov 21, 2024
1828975
fmt
alexarchambault Nov 21, 2024
c9054a3
more
alexarchambault Nov 21, 2024
3dbc225
Starting to look good 🤔
alexarchambault Nov 21, 2024
b260f6f
Merge branch 'main' into pr/bom-support
alexarchambault Nov 21, 2024
e13a102
Merge branch 'main' into pr/bom-support
alexarchambault Nov 22, 2024
9c75f73
Merge branch 'main' into pr/bom-support
alexarchambault Nov 22, 2024
97cb113
more
alexarchambault Nov 22, 2024
13fdbca
Merge branch 'main' into pr/bom-support
alexarchambault Nov 25, 2024
8e28493
more
alexarchambault Nov 25, 2024
7950d4f
fmt
alexarchambault Nov 25, 2024
4f78fe8
Merge branch 'main' into pr/bom-support
alexarchambault Nov 27, 2024
03857e0
Merge branch 'main' into pr/bom-support
alexarchambault Nov 27, 2024
745b500
more - needs clean-up, only checking if CI passes
alexarchambault Nov 27, 2024
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
2 changes: 1 addition & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ object Deps {
val asmTree = ivy"org.ow2.asm:asm-tree:9.7.1"
val bloopConfig = ivy"ch.epfl.scala::bloop-config:1.5.5"

val coursierVersion = "2.1.18"
val coursierVersion = "2.1.19"
val coursier = ivy"io.get-coursier::coursier:$coursierVersion"
val coursierInterface = ivy"io.get-coursier:interface:1.0.24"
val coursierJvm = ivy"io.get-coursier::coursier-jvm:$coursierVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ object DocAnnotationsTests extends UtestIntegrationTestSuite {
|
|Inputs:
| core.transitiveIvyDeps
| core.parentDep
| core.bomDeps
|""".stripMargin,
ivyDepsTree
)
Expand Down
39 changes: 18 additions & 21 deletions main/util/src/mill/util/CoursierSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import coursier.params.ResolutionParams
import coursier.parse.RepositoryParser
import coursier.jvm.{JvmCache, JvmChannel, JvmIndex, JavaHome}
import coursier.util.Task
import coursier.{Artifacts, Classifier, Dependency, Repository, Resolution, Resolve, Type}
import coursier.{Artifacts, Classifier, Dependency, Module, Repository, Resolution, Resolve, Type}
import mill.api.Loose.Agg
import mill.api.{Ctx, PathRef, Result}

Expand All @@ -31,6 +31,20 @@ trait CoursierSupport {
ctx.fold(cache)(c => cache.withLogger(new TickerResolutionLogger(c)))
}

private def isLocalTestDep(dep: Dependency): Option[Seq[PathRef]] = {
val org = dep.module.organization.value
val name = dep.module.name.value
val classpathKey = s"$org-$name"

val classpathResourceText =
try Some(os.read(
os.resource(getClass.getClassLoader) / "mill/local-test-overrides" / classpathKey
))
catch { case e: os.ResourceNotFoundException => None }

classpathResourceText.map(_.linesIterator.map(s => PathRef(os.Path(s))).toSeq)
}

/**
* Resolve dependencies using Coursier.
*
Expand All @@ -51,26 +65,8 @@ trait CoursierSupport {
artifactTypes: Option[Set[Type]] = None,
resolutionParams: ResolutionParams = ResolutionParams()
): Result[Agg[PathRef]] = {
def isLocalTestDep(dep: Dependency): Option[Seq[PathRef]] = {
val org = dep.module.organization.value
val name = dep.module.name.value
val classpathKey = s"$org-$name"

val classpathResourceText =
try Some(os.read(
os.resource(getClass.getClassLoader) / "mill/local-test-overrides" / classpathKey
))
catch { case e: os.ResourceNotFoundException => None }

classpathResourceText.map(_.linesIterator.map(s => PathRef(os.Path(s))).toSeq)
}

val (localTestDeps, remoteDeps) = deps.iterator.toSeq.partitionMap(d =>
isLocalTestDep(d) match {
case None => Right(d)
case Some(vs) => Left(vs)
}
)
val (localTestDeps, remoteDeps) =
deps.iterator.toSeq.partitionMap(d => isLocalTestDep(d).toLeft(d))

val resolutionRes = resolveDependenciesMetadataSafe(
repositories,
Expand Down Expand Up @@ -262,6 +258,7 @@ trait CoursierSupport {

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

val forceVersions = force.iterator
Expand Down
46 changes: 44 additions & 2 deletions scalalib/src/mill/scalalib/CoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package mill.scalalib

import coursier.cache.FileCache
import coursier.params.ResolutionParams
import coursier.{Dependency, Repository, Resolve, Type}
import coursier.core.Resolution
import coursier.{Dependency, Module, Repository, Resolve, Type}
import coursier.core.{DependencyManagement, Resolution}
import mill.define.Task
import mill.api.PathRef

Expand Down Expand Up @@ -216,6 +216,48 @@ object CoursierModule {
sources: Boolean
): Agg[PathRef] =
resolveDeps(deps, sources, None)

/**
* Processes dependencies and BOMs with coursier
*
* This makes coursier read and process BOM dependencies, and fill version placeholders
* in dependencies with the BOMs.
*
* Note that this doesn't throw when a version placeholder cannot be filled, and just leaves
* the placeholder behind.
*
* @param deps dependencies that might have placeholder versions ("_" as version)
* @param resolutionParams coursier resolution parameters
* @return dependencies with version placeholder filled and data read from the BOM dependencies
*/
def processDeps[T: CoursierModule.Resolvable](
deps: IterableOnce[T],
resolutionParams: ResolutionParams = ResolutionParams()
): (Seq[Dependency], DependencyManagement.Map) = {
val deps0 = deps
.map(implicitly[CoursierModule.Resolvable[T]].bind(_, bind))
val res = Lib.resolveDependenciesMetadataSafe(
repositories = repositories,
deps = deps0,
mapDependencies = mapDependencies,
customizer = customizer,
coursierCacheCustomizer = coursierCacheCustomizer,
ctx = ctx,
resolutionParams = resolutionParams
).getOrThrow
val depMgmt: DependencyManagement.Map =
if (res.processedRootDependencies.isEmpty) Map.empty
else {
val overrides = res.processedRootDependencies.map(_.overrides)
overrides.tail.foldLeft(overrides.head) { (acc, map) =>
acc.filter {
case (key, values) =>
map.get(key).contains(values)
}
}
}
(res.processedRootDependencies, depMgmt)
}
}

sealed trait Resolvable[T] {
Expand Down
2 changes: 2 additions & 0 deletions scalalib/src/mill/scalalib/Dep.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ object Dep {
}

(module.split(':') match {
case Array(a, b) => Dep(a, b, "_", cross = empty(platformed = false))
case Array(a, "", b) => Dep(a, b, "_", cross = Binary(platformed = false))
case Array(a, b, c) => Dep(a, b, c, cross = empty(platformed = false))
case Array(a, b, "", c) => Dep(a, b, c, cross = empty(platformed = true))
case Array(a, "", b, c) => Dep(a, b, c, cross = Binary(platformed = false))
Expand Down
Loading
Loading