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

Overhaul transitive module handling in dependency resolution #4145

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
95f49f9
Overhaul transitive module handling in dep resolution
alexarchambault Dec 16, 2024
a561284
fixes
alexarchambault Dec 17, 2024
9434d99
Update coursier to 2.1.22
alexarchambault Dec 17, 2024
ca347cc
Temporary - drop resolveFilters
alexarchambault Dec 18, 2024
b1eff1c
Fix
alexarchambault Dec 18, 2024
24714ed
Get rid of resolveFilter stuff
alexarchambault Dec 18, 2024
e1c1daa
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Dec 18, 2024
275f54d
Missing bits from #4162
alexarchambault Dec 18, 2024
5c90bb0
Fix bin compat
alexarchambault Dec 18, 2024
1a8a3d2
add docs, tweak things
alexarchambault Dec 18, 2024
c6c8a7e
Add doc, plus fixes / guards
alexarchambault Dec 18, 2024
191bf54
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Dec 27, 2024
d9195df
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Jan 7, 2025
6f39c72
Tweaking
alexarchambault Jan 7, 2025
31f610d
Update BspServerTests test data
alexarchambault Jan 7, 2025
4f293a3
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Jan 7, 2025
aa5e418
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Jan 8, 2025
2098054
Cache test module overrides read attempts
alexarchambault Jan 8, 2025
feda739
Better error messages
alexarchambault Jan 8, 2025
b970a90
debug bootstrap job
alexarchambault Jan 8, 2025
e1c02eb
debug deadlock issue on CI
alexarchambault Jan 8, 2025
8b8db3c
fixup
alexarchambault Jan 8, 2025
9c2e634
fixup
alexarchambault Jan 8, 2025
84d8a4d
debug
alexarchambault Jan 8, 2025
10601aa
?
alexarchambault Jan 8, 2025
222efe7
Revert "debug"
alexarchambault Jan 8, 2025
90f93e9
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Jan 8, 2025
1f46568
More debugging
alexarchambault Jan 8, 2025
7ad6ff4
check
alexarchambault Jan 8, 2025
db7af84
other check
alexarchambault Jan 8, 2025
8f8ecb0
Revert "check"
alexarchambault Jan 8, 2025
c5dc629
Tweaking
alexarchambault Jan 8, 2025
e1f5d8f
Don't change default stderr
alexarchambault Jan 8, 2025
a122015
last check
alexarchambault Jan 8, 2025
30462a2
?
alexarchambault Jan 8, 2025
5527736
Revert debug stuff
alexarchambault Jan 8, 2025
847462b
fmt
alexarchambault Jan 8, 2025
b9ee650
Update BSP test snapshots
alexarchambault Jan 8, 2025
4c0a06f
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Jan 9, 2025
b5611cf
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Jan 13, 2025
2c6b737
Tweak things / add comments
alexarchambault Jan 13, 2025
da17946
Fix version in new deprecation messages
alexarchambault Jan 13, 2025
7ac0124
Fix new import order
alexarchambault Jan 13, 2025
0d8d34d
Revert BSP benchmark change
alexarchambault Jan 13, 2025
536d958
Copy comment
alexarchambault Jan 14, 2025
685fb8d
Merge branch 'main' into pr/java-module-cs-project
alexarchambault Jan 15, 2025
1ab71c9
Fix out-files test
alexarchambault Jan 15, 2025
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
28 changes: 21 additions & 7 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ private class MillBuildServer(
Task.Anon {
(
m.defaultResolver().resolveDeps(
m.transitiveCompileIvyDeps() ++ m.transitiveIvyDeps(),
Seq(
m.coursierDependency.withConfiguration(coursier.core.Configuration.provided),
m.coursierDependency
),
sources = true
),
m.unmanagedClasspath(),
Expand Down Expand Up @@ -332,22 +335,33 @@ private class MillBuildServer(
hint = "buildTargetDependencyModules",
targetIds = _ => params.getTargets.asScala.toSeq,
tasks = { case m: JavaModule =>
Task.Anon { (m.transitiveCompileIvyDeps(), m.transitiveIvyDeps(), m.unmanagedClasspath()) }
Task.Anon {
(
// full list of dependencies, including transitive ones
m.defaultResolver().allDeps(
Seq(
m.coursierDependency.withConfiguration(coursier.core.Configuration.provided),
m.coursierDependency
)
),
m.unmanagedClasspath()
)
}
}
) {
case (
ev,
state,
id,
m: JavaModule,
(transitiveCompileIvyDeps, transitiveIvyDeps, unmanagedClasspath)
(ivyDeps, unmanagedClasspath)
) =>
val ivy = transitiveCompileIvyDeps ++ transitiveIvyDeps
val deps = ivy.map { dep =>
// TODO: add data with "maven" data kind using a ...
val deps = ivyDeps.collect {
case dep if dep.module.organization != JavaModule.internalOrg =>
// TODO: add data with "maven" data kind using a ...
// MavenDependencyModule

new DependencyModule(dep.dep.module.repr, dep.dep.version)
new DependencyModule(dep.module.repr, dep.version)
}
val unmanaged = unmanagedClasspath.map { dep =>
new DependencyModule(s"unmanaged-${dep.path.last}", "")
Expand Down
4 changes: 4 additions & 0 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ trait MillStableScalaModule extends MillPublishScalaModule with Mima {
"mill.main.MainModule.mill$define$BaseModule0$_setter_$evalWatchedValues_="
),

// Overrides added for new methods, ought to be safe
ProblemFilter.exclude[ReversedMissingMethodProblem]("mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$internalRepositories"),
ProblemFilter.exclude[ReversedMissingMethodProblem]("mill.scalanativelib.ScalaNativeModule.mill$scalanativelib$ScalaNativeModule$$super$coursierProject"),

Comment on lines +595 to +597
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexarchambault these turn out not to be safe, we probably need to fix the code to not add calls to super since they are not binary compatible

CC @sake92

Copy link
Member

@lefou lefou Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I said it before, but I suggest to generate the access to super.<overridden> from our macros as soon as we can break bin-compat, so that we better prepare the binary code for ad-hoc overriding of tasks. The super-calls can be left unused, so they should not affect functionality, but we at least we trigger the super-accessors to be present in the binary code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to address that in #4380, although the workarounds aren't fully satisfying IMO (they assume users don't add overrides between the trait defining the method and the one overriding it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other such changes adding calls to super have been introduced in the past, apparently:

mill/build.mill

Lines 523 to 580 in 9815c35

ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$scalaLibraryIvyDeps"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.ScalaModule.mill$scalalib$ScalaModule$$super$zincAuxiliaryClassFileExtensions"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$zincAuxiliaryClassFileExtensions"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalanativelib.ScalaNativeModule.mill$scalanativelib$ScalaNativeModule$$super$zincAuxiliaryClassFileExtensions"
),
// (6x) See https://github.com/com-lihaoyi/mill/pull/3064
// Moved targets up in trait hierarchy, but also call them via super, which I think is safe
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$zincWorker"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$runClasspath"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$runUseArgsFile"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$forkArgs"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$forkEnv"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$forkWorkingDir"
),
// (8x)
// Moved targets up in trait hierarchy, but also call them via super, which I think is safe
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$localRunClasspath"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$runLocal"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$run"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$doRunBackground"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$runBackgroundLogToConsole"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$runMainBackground"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$runMainLocal"
),
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.JavaModule.mill$scalalib$JavaModule$$super$runMain"
),

// https://github.com/com-lihaoyi/mill/pull/3503
ProblemFilter.exclude[ReversedMissingMethodProblem](
"mill.scalalib.ScalaModule#ScalaTests.mill$scalalib$ScalaModule$ScalaTests$$super$mandatoryScalacOptions"
Expand Down
6 changes: 4 additions & 2 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,10 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
val bloopResolution: Task[BloopConfig.Resolution] = Task.Anon {
val repos = module.repositoriesTask()
// same as input of resolvedIvyDeps
val allIvyDeps = module.transitiveIvyDeps() ++ module.transitiveCompileIvyDeps()
val coursierDeps = allIvyDeps.map(_.dep).toList
val coursierDeps = Seq(
module.coursierDependency.withConfiguration(coursier.core.Configuration.provided),
module.coursierDependency
)
BloopConfig.Resolution(artifacts(repos, coursierDeps))
}

Expand Down
6 changes: 4 additions & 2 deletions contrib/playlib/src/mill/playlib/Static.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ trait Static extends ScalaModule {
}

/**
* webjar dependencies - created from transitive ivy deps
* webjar dependencies - created from ivy deps
*/
def webJarDeps = Task {
transitiveIvyDeps().filter(_.dep.module.organization.value == "org.webjars")
ivyDeps()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This slightly changes the semantics of the previous code. Before, ivyDeps of the moduleDeps (and their own moduleDeps, etc.) were taken into account. Now, only the ivyDeps of the current module are.

Alternatively, we could have a look at the whole dependency graph (including external transitive dependencies). But only looking at direct dependencies of the Mill modules looks odd to me (what if the Mill project is split or is a merge of two Mill projects - that changes the value of this task, while it shouldn't IMO).

.filter(_.dep.module.organization.value == "org.webjars")
.map(bindDependency())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ trait ScalaPBModule extends ScalaModule {
else Task { Seq.empty[PathRef] }

def scalaPBProtoClasspath: T[Agg[PathRef]] = Task {
defaultResolver().resolveDeps(transitiveCompileIvyDeps() ++ transitiveIvyDeps())
defaultResolver().resolveDeps(
Seq(
coursierDependency.withConfiguration(coursier.core.Configuration.provided),
coursierDependency
)
)
}

def scalaPBUnpackProto: T[PathRef] = Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
override def sources: T[Seq[PathRef]] = Task { outer.sources() }
override def resources: T[Seq[PathRef]] = Task { outer.resources() }
override def scalaVersion = Task { outer.scalaVersion() }
override def repositoriesTask: Task[Seq[Repository]] = Task.Anon { outer.repositoriesTask() }
override def repositoriesTask: Task[Seq[Repository]] = Task.Anon {
internalRepositories() ++ outer.repositoriesTask()
}
override def compileIvyDeps: T[Agg[Dep]] = Task { outer.compileIvyDeps() }
override def ivyDeps: T[Agg[Dep]] =
Task { outer.ivyDeps() ++ outer.scoverageRuntimeDeps() }
Expand Down
1 change: 0 additions & 1 deletion example/cli/builtins/1-builtin-commands/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ foo.unmanagedClasspath
foo.compileIvyDeps
...
foo.ivyDeps
foo.transitiveIvyDeps
foo.compileClasspath

*/
Expand Down
6 changes: 3 additions & 3 deletions example/fundamentals/out-dir/1-out-files/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ out/mill-server

> cat out/mill-build/methodCodeHashSignatures.dest/current/spanningInvalidationTree.json
{
"call scala.runtime.BoxesRunTime.boxToInteger(int)java.lang.Integer": {
"call scala.runtime.BoxesRunTime.boxToInteger(int)java.lang.Integer": {},
"call scala.Predef$#println(java.lang.Object)void": {
"def build_.package_$foo$#<init>(build_.package_)void": {
"call build_.package_$foo$!<init>(build_.package_)void": {
"def build_.package_#foo$lzycompute$1()void": {
Expand All @@ -253,8 +254,7 @@ out/mill-server
}
}
}
},
"call scala.Predef$#println(java.lang.Object)void": {}
}
}

*/
Expand Down
5 changes: 4 additions & 1 deletion idea/src/mill/idea/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ case class GenIdeaImpl(

// same as input of resolvedIvyDeps
val allIvyDeps = Task.Anon {
mod.transitiveIvyDeps() ++ mod.transitiveCompileIvyDeps()
Agg(
mod.coursierDependency,
mod.coursierDependency.withConfiguration(coursier.core.Configuration.provided)
).map(BoundDep(_, force = false))
}

val scalaCompilerClasspath = mod match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ object DocAnnotationsTests extends UtestIntegrationTestSuite {
| tree.
|
|Inputs:
| core.transitiveIvyDeps
| core.mandatoryIvyDeps
| core.ivyDeps
| core.compileIvyDeps
| core.runIvyDeps
| core.bomIvyDeps
| core.depManagement
|""".stripMargin,
ivyDepsTree
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{
"name": "org.slf4j:slf4j-api",
"version": "2.0.16"
},
{
"name": "org.hamcrest:hamcrest-core",
"version": "1.3"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file are a good thing: rather than including only dependencies directly added in Mill modules (via transitiveIvyDeps and all), this adds the whole dependency graph (including transitive dependencies pulled externally). IIUC, this is what is expected from that BSP request.

}
]
},
Expand All @@ -44,6 +48,10 @@
{
"name": "org.jetbrains.kotlin:kotlin-stdlib",
"version": "<kotlin-version>"
},
{
"name": "org.jetbrains:annotations",
"version": "13.0"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"uri": "file:///workspace/app"
},
"classpath": [
"file:///coursier-cache/https/repo1.maven.org/maven2/com/mysql/mysql-connector-j/9.1.0/mysql-connector-j-9.1.0.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/ch/qos/logback/logback-core/1.5.15/logback-core-1.5.15.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/com/mysql/mysql-connector-j/9.1.0/mysql-connector-j-9.1.0.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.16/slf4j-api-2.0.16.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.26.1/protobuf-java-4.26.1.jar",
"file:///workspace/lib/compile-resources",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"uri": "file:///workspace/app"
},
"classpath": [
"file:///coursier-cache/https/repo1.maven.org/maven2/com/mysql/mysql-connector-j/9.1.0/mysql-connector-j-9.1.0.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/ch/qos/logback/logback-core/1.5.15/logback-core-1.5.15.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/com/mysql/mysql-connector-j/9.1.0/mysql-connector-j-9.1.0.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.16/slf4j-api-2.0.16.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.26.1/protobuf-java-4.26.1.jar",
"file:///workspace/lib/compile-resources",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<orderEntry type="library" name="scala-js-SDK-3.3.1" level="project"/>
<orderEntry type="library" name="portable-scala-reflect_sjs1_2.13-1.1.3.jar" level="project"/>
<orderEntry type="library" name="scala-library-2.13.13.jar" level="project"/>
<orderEntry type="library" name="scala3-library_sjs1_3-3.3.1.jar" level="project"/>
<orderEntry type="library" name="scala3-library_sjs1_3-3.3.3.jar" level="project"/>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't investigate why the version is bumped here. That doesn't look like a major issue though…

<orderEntry type="library" name="scalajs-javalib-1.16.0.jar" level="project"/>
<orderEntry type="library" name="scalajs-library_2.13-1.16.0.jar" level="project"/>
<orderEntry type="library" name="scalajs-scalalib_2.13-2.13.13%2B1.16.0.jar" level="project"/>
Expand Down
2 changes: 2 additions & 0 deletions main/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ object `package` extends RootModule with build.MillStableScalaModule with BuildI
// Lib.resolveDependenciesMetadataSafe(
Lib.resolveDependenciesMetadata(
repositories = build.dist.repositoriesTask(),
// When re-bootstraping Mill, replace the next line with
// Seq(BoundDep(build.dist.coursierDependency(), force = false)),
build.dist.transitiveIvyDeps(),
Some(build.dist.mapDependencies()),
build.dist.resolutionCustomizer(),
Expand Down
112 changes: 93 additions & 19 deletions main/util/src/mill/util/CoursierSupport.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package mill.util

import coursier.cache.{CacheLogger, FileCache}
import coursier.core.BomDependency
import coursier.core.{ArtifactSource, BomDependency, Extension, Info, Module, Project, Publication}
import coursier.error.FetchError.DownloadingArtifacts
import coursier.error.ResolutionError.CantDownloadModule
import coursier.params.ResolutionParams
import coursier.parse.RepositoryParser
import coursier.jvm.{JvmCache, JvmChannel, JvmIndex, JavaHome}
import coursier.util.Task
import coursier.util.{Artifact, EitherT, Monad, Task}
import coursier.{Artifacts, Classifier, Dependency, Repository, Resolution, Resolve, Type}
import mill.api.Loose.Agg
import mill.api.{Ctx, PathRef, Result}

import java.util.concurrent.ConcurrentHashMap

import scala.collection.mutable
import scala.util.chaining.scalaUtilChainingOps
import coursier.cache.ArchiveCache
Expand All @@ -32,18 +34,91 @@ 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"
/**
* A `coursier.Repository` that exposes modules with hard-coded artifact list
*
* Used in Mill tests. This exposes internal workers for example, so that these
* come from the build and not from remote repositories or ~/.ivy2/local. See
* `MillJavaModule#{testTransitiveDeps,writeLocalTestOverrides}` in the Mill build.
*/
private final class TestOverridesRepo(root: os.ResourcePath) extends Repository {

private val map = new ConcurrentHashMap[Module, Option[String]]

private def listFor(mod: Module): Either[os.ResourceNotFoundException, String] = {

def entryPath = root / s"${mod.organization.value}-${mod.name.value}"

val inCacheOpt = Option(map.get(mod))

inCacheOpt
.getOrElse {

val computedOpt =
try Some(os.read(entryPath))
catch {
case _: os.ResourceNotFoundException =>
None
}
val concurrentOpt = Option(map.putIfAbsent(mod, computedOpt))
concurrentOpt.getOrElse(computedOpt)
}
.toRight {
new os.ResourceNotFoundException(entryPath)
}
}

val classpathResourceText =
try Some(os.read(
os.resource(getClass.getClassLoader) / "mill/local-test-overrides" / classpathKey
))
catch { case e: os.ResourceNotFoundException => None }
def find[F[_]: Monad](
module: Module,
version: String,
fetch: Repository.Fetch[F]
): EitherT[F, String, (ArtifactSource, Project)] =
EitherT.fromEither[F] {
listFor(module)
.left.map(e => s"No test override found at ${e.path}")
.map { _ =>
val proj = Project(
module,
version,
dependencies = Nil,
configurations = Map.empty,
parent = None,
dependencyManagement = Nil,
properties = Nil,
profiles = Nil,
versions = None,
snapshotVersioning = None,
packagingOpt = None,
relocated = false,
actualVersionOpt = None,
publications = Nil,
info = Info.empty
)
(this, proj)
}
}

classpathResourceText.map(_.linesIterator.map(s => PathRef(os.Path(s))).toSeq)
def artifacts(
dependency: Dependency,
project: Project,
overrideClassifiers: Option[Seq[Classifier]]
): Seq[(Publication, Artifact)] =
listFor(project.module)
.toTry.get
.linesIterator
.map(os.Path(_))
.filter(os.exists)
.map { path =>
val pub = Publication(
if (path.last.endsWith(".jar")) path.last.stripSuffix(".jar") else path.last,
Type.jar,
Extension.jar,
Classifier.empty
)
val art = Artifact(path.toNIO.toUri.toASCIIString)
(pub, art)
}
.toSeq
}

/**
Expand Down Expand Up @@ -74,12 +149,9 @@ trait CoursierSupport {
artifactTypes: Option[Set[Type]] = None,
resolutionParams: ResolutionParams = ResolutionParams()
): Result[Agg[PathRef]] = {
val (localTestDeps, remoteDeps) =
deps.iterator.toSeq.partitionMap(d => isLocalTestDep(d).toLeft(d))

val resolutionRes = resolveDependenciesMetadataSafe(
repositories,
remoteDeps,
deps,
force,
mapDependencies,
customizer,
Expand Down Expand Up @@ -118,7 +190,7 @@ trait CoursierSupport {
.map(os.Path(_))
.filter(deprecatedResolveFilter)
.map(PathRef(_, quick = true))
) ++ localTestDeps.flatten
)
)
}
}
Expand Down Expand Up @@ -275,7 +347,6 @@ trait CoursierSupport {

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

val forceVersions = force.iterator
Expand All @@ -288,10 +359,13 @@ trait CoursierSupport {
val resolutionParams0 = resolutionParams
.addForceVersion(forceVersions.toSeq: _*)

val testOverridesRepo =
new TestOverridesRepo(os.resource(getClass.getClassLoader) / "mill/local-test-overrides")

val resolve = Resolve()
.withCache(coursierCache0)
.withDependencies(rootDeps)
.withRepositories(repositories)
.withRepositories(testOverridesRepo +: repositories)
.withResolutionParams(resolutionParams0)
.withMapDependenciesOpt(mapDependencies)
.withBoms(boms.toSeq)
Expand Down
Loading
Loading