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

Apply coursier default config files (repositories and mirrors config) #2886

Merged
merged 2 commits into from
Dec 1, 2023
Merged
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
9 changes: 8 additions & 1 deletion scalalib/src/mill/scalalib/CoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import mill.define.Task
import mill.api.PathRef

import scala.annotation.nowarn
import scala.concurrent.Await
import scala.concurrent.duration.Duration

/**
* This module provides the capability to resolve (transitive) dependencies from (remote) repositories.
Expand Down Expand Up @@ -60,7 +62,12 @@ trait CoursierModule extends mill.Module {
* The repositories used to resolved dependencies with [[resolveDeps()]].
*/
def repositoriesTask: Task[Seq[Repository]] = T.task {
Resolve.defaultRepositories
import scala.concurrent.ExecutionContext.Implicits.global
val repos = Await.result(
Resolve().finalRepositories.future(),
Duration.Inf
)
repos
}

/**
Expand Down
2 changes: 2 additions & 0 deletions scalalib/test/resources/coursier/mirror.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
central.from=https://repo1.maven.org/maven2
central.to=https://repo.maven.apache.org/maven2/
42 changes: 42 additions & 0 deletions scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package mill.scalalib

import mill.util.{TestEvaluator, TestUtil}
import mill.eval.{Evaluator}
import utest._
import utest.framework.TestPath

object CoursierMirrorTests extends TestSuite {

val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "coursier"

object CoursierTest extends TestUtil.BaseModule {
object core extends ScalaModule {
def scalaVersion = "2.13.12"
}
}

def workspaceTest[T](
m: TestUtil.BaseModule,
resourcePath: os.Path = resourcePath,
env: Map[String, String] = Evaluator.defaultEnv,
debug: Boolean = false
)(t: TestEvaluator => T)(implicit tp: TestPath): T = {
val eval = new TestEvaluator(m, env = env, debugEnabled = debug)
os.remove.all(m.millSourcePath)
os.remove.all(eval.outPath)
os.makeDir.all(m.millSourcePath / os.up)
os.copy(resourcePath, m.millSourcePath)
t(eval)
}

def tests: Tests = Tests {
sys.props("coursier.mirrors") = (resourcePath / "mirror.properties").toString
"readMirror" - workspaceTest(CoursierTest) { eval =>
val Right((result, evalCount)) = eval.apply(CoursierTest.core.repositoriesTask)
val centralReplaced = result.exists { repo =>
repo.repr.contains("https://repo.maven.apache.org/maven2")
}
assert(centralReplaced)
}
}
}