From 3adc4adede7ac0c7993535b374ef4600382ff75d Mon Sep 17 00:00:00 2001 From: Andrew Richards Date: Sat, 3 Mar 2018 21:53:49 +0100 Subject: factor out Dependency creation in Lib so it can be reused (#137) * factor out Dependency creation in Lib so it can be reused * fix indenting * really fix indenting * third time lucky --- scalalib/src/mill/scalalib/Lib.scala | 38 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala index 208d545e..420075fe 100644 --- a/scalalib/src/mill/scalalib/Lib.scala +++ b/scalalib/src/mill/scalalib/Lib.scala @@ -4,11 +4,10 @@ package scalalib import java.io.File import ammonite.ops._ -import coursier.{Cache, Fetch, MavenRepository, Repository, Resolution, Module => CoursierModule} +import coursier.{Cache, Fetch, MavenRepository, Repository, Resolution, Dependency, Module => CoursierModule} import mill.eval.{PathRef, Result} import mill.util.Loose.Agg - object CompilationResult { implicit val jsonFormatter: upickle.default.ReadWriter[CompilationResult] = upickle.default.macroRW } @@ -27,20 +26,8 @@ object Lib{ .toIO } - /** - * Resolve dependencies using Coursier. - * - * We do not bother breaking this out into the separate ScalaWorker classpath, - * because Coursier is already bundled with mill/Ammonite to support the - * `import $ivy` syntax. - */ - def resolveDependencies(repositories: Seq[Repository], - scalaVersion: String, - deps: TraversableOnce[Dep], - platformSuffix: String = "", - sources: Boolean = false): Result[Agg[PathRef]] = { - - val flattened = deps.map{ + def depToDependency(dep: Dep, scalaVersion: String, platformSuffix: String = ""): Dependency = + dep match { case Dep.Java(dep, cross) => dep.copy( module = dep.module.copy( @@ -67,7 +54,24 @@ object Lib{ "_" + scalaVersion ) ) - }.toSet + } + + + + /** + * Resolve dependencies using Coursier. + * + * We do not bother breaking this out into the separate ScalaWorker classpath, + * because Coursier is already bundled with mill/Ammonite to support the + * `import $ivy` syntax. + */ + def resolveDependencies(repositories: Seq[Repository], + scalaVersion: String, + deps: TraversableOnce[Dep], + platformSuffix: String = "", + sources: Boolean = false): Result[Agg[PathRef]] = { + + val flattened = deps.map(depToDependency(_, scalaVersion, platformSuffix)).toSet val start = Resolution(flattened) val fetch = Fetch.from(repositories, Cache.fetch()) -- cgit v1.2.3