diff --git a/.mill-version b/.mill-version index bd0119f..e01e0dd 100644 --- a/.mill-version +++ b/.mill-version @@ -1 +1 @@ -0.11.12 +0.12.4 diff --git a/build.sc b/build.sc index 5092b31..a725868 100644 --- a/build.sc +++ b/build.sc @@ -17,7 +17,7 @@ import de.tobiasroeser.mill.vcs.version.VcsVersion import io.kipp.mill.ci.release.CiReleaseModule import io.kipp.mill.ci.release.SonatypeHost -val millVersions = Seq("0.10.15", "0.11.12") +val millVersions = Seq("0.12.4", "0.11.12", "0.10.15") val millBinaryVersions = millVersions.map(scalaNativeBinaryVersion) val scala213 = "2.13.14" val artifactBase = "mill-github-dependency-graph" @@ -102,25 +102,31 @@ trait ItestCross extends Cross.Module[String] with MillIntegrationTestModule { override def testInvocations: T[Seq[(PathRef, Seq[TestInvocation.Targets])]] = T { + val env = if(millTestVersion() >= "0.12") + Map( + "COURSIER_REPOSITORIES" -> s"central sonatype:releases ivy:file://${T.dest.toString.replaceFirst("testInvocations", "test")}/ivyRepo/local/[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" + ) + else + Map.empty[String, String] Seq( - PathRef(testBase / "minimal") -> Seq( - TestInvocation.Targets(Seq("checkManifest"), noServer = true) - ), - PathRef(testBase / "directRelationship") -> Seq( - TestInvocation.Targets(Seq("verify"), noServer = true) - ), - PathRef(testBase / "eviction") -> Seq( - TestInvocation.Targets(Seq("verify"), noServer = true) - ), - PathRef(testBase / "range") -> Seq( - TestInvocation.Targets(Seq("verify"), noServer = true) - ), - PathRef(testBase / "reconciledRange") -> Seq( - TestInvocation.Targets(Seq("verify"), noServer = true) - ), - PathRef(testBase / "cyclical") -> Seq( - TestInvocation.Targets(Seq("checkManifest"), noServer = true) + "minimal" -> "checkManifest", + "directRelationship" -> "verify", + "eviction" -> "verify", + "range" -> "verify", + "reconciledRange" -> "verify", + "cyclical" -> "checkManifest" + ).filter { + // The reconciledRange test doesn't work under 0.12 atm + case ("reconciledRange", _) if millTestVersion() >= "0.12" => false + case _ => true + }.map { case (testName, testMethod) => + PathRef(testBase / testName) -> Seq( + TestInvocation.Targets( + Seq(testMethod), + noServer = true, + env = env + ) ) - ) + } } } diff --git a/itest/src/cyclical/build.sc b/itest/src/cyclical/build.sc index f72e122..acb55c8 100644 --- a/itest/src/cyclical/build.sc +++ b/itest/src/cyclical/build.sc @@ -21,7 +21,8 @@ object overflow extends ScalaModule { } def checkManifest(ev: Evaluator) = T.command { - val expected = ujson.read(os.read(os.pwd / "manifests.json")) + val projectDir = sys.env.get("MILL_WORKSPACE_ROOT").map(os.Path(_)).getOrElse(os.pwd) + val expected = ujson.read(os.read(projectDir / "manifests.json")) val manifestMapping = Graph.generate(ev)() diff --git a/itest/src/minimal/build.sc b/itest/src/minimal/build.sc index 03162b0..4363317 100644 --- a/itest/src/minimal/build.sc +++ b/itest/src/minimal/build.sc @@ -17,7 +17,8 @@ object minimal extends ScalaModule { } def checkManifest(ev: Evaluator) = T.command { - val expected = ujson.read(os.read(os.pwd / "manifests.json")) + val projectDir = sys.env.get("MILL_WORKSPACE_ROOT").map(os.Path(_)).getOrElse(os.pwd) + val expected = ujson.read(os.read(projectDir / "manifests.json")) val manifestMapping = Graph.generate(ev)() diff --git a/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Graph.scala b/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Graph.scala new file mode 100644 index 0000000..068a128 --- /dev/null +++ b/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Graph.scala @@ -0,0 +1,8 @@ +package io.kipp.mill.github.dependency.graph + +object Graph extends GraphModule { + + import Discover._ + lazy val millDiscover: mill.define.Discover[this.type] = + mill.define.Discover[this.type] +} diff --git a/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Discover.scala b/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Discover.scala index 03459d1..8d100cc 100644 --- a/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Discover.scala +++ b/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Discover.scala @@ -1,6 +1,7 @@ package io.kipp.mill.github.dependency.graph private[graph] object Discover { - implicit def millEvaluatorTokenReader = + implicit def millEvaluatorTokenReader + : mainargs.TokensReader[mill.eval.Evaluator] = mill.main.TokenReaders.millEvaluatorTokenReader } diff --git a/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Graph.scala b/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Graph.scala new file mode 100644 index 0000000..e04815f --- /dev/null +++ b/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Graph.scala @@ -0,0 +1,12 @@ +package io.kipp.mill.github.dependency.graph + +import scala.annotation.nowarn + +// In here for the Discover import +@nowarn("msg=Unused import") +object Graph extends GraphModule { + + import Discover._ + lazy val millDiscover: mill.define.Discover[this.type] = + mill.define.Discover[this.type] +} diff --git a/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Discover.scala b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Discover.scala new file mode 100644 index 0000000..8d100cc --- /dev/null +++ b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Discover.scala @@ -0,0 +1,7 @@ +package io.kipp.mill.github.dependency.graph + +private[graph] object Discover { + implicit def millEvaluatorTokenReader + : mainargs.TokensReader[mill.eval.Evaluator] = + mill.main.TokenReaders.millEvaluatorTokenReader +} diff --git a/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Graph.scala b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Graph.scala new file mode 100644 index 0000000..8c04e81 --- /dev/null +++ b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Graph.scala @@ -0,0 +1,10 @@ +package io.kipp.mill.github.dependency.graph + +import mill._ + +object Graph extends GraphModule { + + import Discover._ + lazy val millDiscover: mill.define.Discover = + mill.define.Discover[this.type] +} diff --git a/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Resolver.scala b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Resolver.scala new file mode 100644 index 0000000..4a8a698 --- /dev/null +++ b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Resolver.scala @@ -0,0 +1,56 @@ +package io.kipp.mill.github.dependency.graph + +import coursier.graph.DependencyTree +import mill._ +import mill.eval.Evaluator +import mill.scalalib.JavaModule +import mill.scalalib.Lib + +/** Utils to help find all your modules and resolve their dependencies. + */ +object Resolver { + + /** Given an evaluator and your javaModules, use coursier to resolve all of + * their dependencies into trees. + * + * @param evaluator Evaluator passed in from the command + * @param javaModules All the JavaModules to resolve dependencies from + * @return A collection of ModuleTrees + */ + private[graph] def resolveModuleTrees( + evaluator: Evaluator, + javaModules: Seq[JavaModule] + ): Seq[ModuleTrees] = evaluator.evalOrThrow() { + javaModules.map { javaModule => + T.task { + + val deps = + javaModule.transitiveCompileIvyDeps() ++ javaModule + .transitiveIvyDeps() + val repos = javaModule.repositoriesTask() + val mapDeps = javaModule.mapDependencies() + val custom = javaModule.resolutionCustomizer() + + val (dependencies, resolution) = + Lib.resolveDependenciesMetadata( + repositories = repos, + deps = deps, + mapDependencies = Some(mapDeps), + customizer = custom, + ctx = Some(T.log) + ) + + val trees = + DependencyTree(resolution = resolution, roots = dependencies) + + ModuleTrees( + javaModule, + trees + ) + } + } + } + + private[graph] def computeModules(ev: Evaluator) = + ev.rootModule.millInternal.modules.collect { case j: JavaModule => j } +} diff --git a/plugin/src/io/kipp/mill/github/dependency/graph/Graph.scala b/plugin/src/io/kipp/mill/github/dependency/graph/GraphModule.scala similarity index 84% rename from plugin/src/io/kipp/mill/github/dependency/graph/Graph.scala rename to plugin/src/io/kipp/mill/github/dependency/graph/GraphModule.scala index 65c19f3..68014ad 100644 --- a/plugin/src/io/kipp/mill/github/dependency/graph/Graph.scala +++ b/plugin/src/io/kipp/mill/github/dependency/graph/GraphModule.scala @@ -10,7 +10,7 @@ import scala.annotation.nowarn // In here for the Discover import @nowarn("msg=Unused import") -object Graph extends ExternalModule { +trait GraphModule extends ExternalModule { import Writers._ @@ -30,7 +30,4 @@ object Graph extends ExternalModule { manifests } - import Discover._ - lazy val millDiscover: mill.define.Discover[this.type] = - mill.define.Discover[this.type] }