Skip to content
This repository was archived by the owner on May 4, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: ['8', '17']
java: ['11', '17']

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.12
0.12.4
42 changes: 22 additions & 20 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import $ivy.`com.goyeau::mill-scalafix::0.4.0`
import $ivy.`com.goyeau::mill-scalafix::0.4.2`
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
import $ivy.`de.tototec::de.tobiasroeser.mill.integrationtest::0.7.1`
import $ivy.`io.chris-kipp::mill-ci-release::0.1.10`
Expand All @@ -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"
Expand Down Expand Up @@ -102,25 +102,27 @@ 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]"
Copy link
Owner

Choose a reason for hiding this comment

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

So is this needed now for 0.12 versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this was the only way I found to make Mill / Coursier pick up the local dev repo.
In Mill 0.12+ there is a different way to integration-test Mill plugins, with which this hack/workaround would probably go away. But that doesn't work for 0.10 and 0.11, so I guess it's best to live with the workaround until usage of Mill < 0.12 dies out and one can completely switch to the new approach.

)
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"
).map { case (testName, testMethod) =>
PathRef(testBase / testName) -> Seq(
TestInvocation.Targets(
Seq(testMethod),
noServer = true,
env = env
)
)
)
}
}
}
3 changes: 2 additions & 1 deletion itest/src/cyclical/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Iterator.iterate(os.pwd)(_ / os.up).find(dir => os.exists(dir / "manifests.json")).get
val expected = ujson.read(os.read(projectDir / "manifests.json"))

val manifestMapping = Graph.generate(ev)()

Expand Down
3 changes: 2 additions & 1 deletion itest/src/minimal/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Iterator.iterate(os.pwd)(_ / os.up).find(dir => os.exists(dir / "manifests.json")).get
val expected = ujson.read(os.read(projectDir / "manifests.json"))

val manifestMapping = Graph.generate(ev)()

Expand Down
4 changes: 2 additions & 2 deletions itest/src/reconciledRange/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object minimalDep extends ScalaModule {
def scalaVersion = "2.13.8"

def ivyDeps = Agg(
ivy"com.fasterxml.jackson.core:jackson-core:2.13.3"
ivy"com.fasterxml.jackson.core:jackson-core:2.12.3"
)
}

Expand Down Expand Up @@ -50,7 +50,7 @@ def verify(ev: Evaluator) = T.command {
// out to ensure we're not creating invalid PURLs.
val expected = Set(
"org.scala-lang:scala-library:2.13.8",
"com.fasterxml.jackson.core:jackson-core:2.13.3",
"com.fasterxml.jackson.core:jackson-core:2.12.3",
// NOTICE that com.fasterxml.jackson.core:jackson-core:[2.7.0,2.12.3] is not here
"com.fasterxml.jackson.core:jackson-core:2.12.3",
"com.fasterxml.jackson.core:jackson-databind:2.12.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Resolver {
private[graph] def resolveModuleTrees(
evaluator: Evaluator,
javaModules: Seq[JavaModule]
): Seq[ModuleTrees] = Evaluator.evalOrThrow(evaluator) {
): Seq[ModuleTrees] = evaluator.evalOrThrow() {
javaModules.map { javaModule =>
T.task {

Expand All @@ -40,6 +40,7 @@ object Resolver {
deps = deps,
mapDependencies = Some(mapDeps),
customizer = custom,
coursierCacheCustomizer = None,
ctx = Some(T.log)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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]
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.kipp.mill.github.dependency.graph

object Graph extends GraphModule {

import Discover._
lazy val millDiscover: mill.define.Discover =
mill.define.Discover[this.type]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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 =>
Task.Anon {

val deps =
javaModule.transitiveCompileIvyDeps() ++ javaModule
.transitiveIvyDeps()
val repos = javaModule.repositoriesTask()
val mapDeps = javaModule.mapDependencies()
val custom = javaModule.resolutionCustomizer()

Lib
.resolveDependenciesMetadataSafe(
repositories = repos,
deps = deps,
mapDependencies = Some(mapDeps),
customizer = custom,
ctx = Some(T.log)
)
.map { resolution =>
val trees =
DependencyTree(
resolution = resolution,
roots = deps.map(_.dep).toSeq
)

ModuleTrees(
javaModule,
trees
)

}

}
}
}

private[graph] def computeModules(ev: Evaluator) =
ev.rootModule.millInternal.modules.collect { case j: JavaModule => j }
}
10 changes: 5 additions & 5 deletions plugin/src/io/kipp/mill/github/dependency/graph/Github.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.kipp.github.dependency.graph.domain.Detector
import io.kipp.github.dependency.graph.domain.Job
import io.kipp.github.dependency.graph.domain.Manifest

import java.net.URL
import java.net.URI
import java.time.Instant
import scala.util.Properties

Expand All @@ -16,7 +16,7 @@ import Writers._
*/
object Github {

private val url = new URL(
private val url = new URI(
s"${Env.githubApiUrl}/repos/${Env.githubRepository}/dependency-graph/snapshots"
)

Expand All @@ -29,7 +29,7 @@ object Github {
ctx.log.info("Submitting your snapshot to GitHub...")
val payload = upickle.default.write(snapshot)
val result = requests.post(
url.toString(),
url.toString,
headers = Map(
"Content-Type" -> "application/json",
"Authorization" -> s"token ${Env.githubToken}"
Expand All @@ -43,7 +43,7 @@ object Github {
val totalDependencies =
snapshot.manifests.values.foldLeft[Seq[String]](Seq.empty) {
(total, manifest) =>
total ++ manifest.resolved.map(_._1)
total ++ manifest.resolved.keys
}
val totalSize = totalDependencies.size
val uniqueSize = totalDependencies.toSet.size
Expand All @@ -69,7 +69,7 @@ object Github {
val msg =
s"""It looks like something went wrong when trying to submit your dependency graph.
|
|[${result.statusCode}] ${result.statusMessage}""".stripMargin
|[${result.statusCode}] ${result.data}""".stripMargin
throw new Exception(msg)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import mill.define.Command
import mill.define.ExternalModule
import mill.eval.Evaluator

import scala.annotation.nowarn

// In here for the Discover import
@nowarn("msg=Unused import")
object Graph extends ExternalModule {
trait GraphModule extends ExternalModule {

import Writers._

Expand All @@ -30,7 +26,4 @@ object Graph extends ExternalModule {
manifests
}

import Discover._
lazy val millDiscover: mill.define.Discover[this.type] =
mill.define.Discover[this.type]
}
Loading