Skip to content

Commit

Permalink
Consider more dependencies (compile-only, runtime, mandatory/implicit) (
Browse files Browse the repository at this point in the history
#9)

Fix #7

Pull request: #9
  • Loading branch information
lefou committed Dec 14, 2022
1 parent 328b4ec commit 8ec1321
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions itest/src/minimal/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ object other extends ScalaModule {
def verify(ev: Evaluator) = T.command {
val str = StewardPlugin.extractDeps(ev)().toString
assert(str.contains("munit_3"))
assert(str.contains("scala-library"))
}
41 changes: 29 additions & 12 deletions plugin/src/org/scalasteward/mill/plugin/StewardPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import mill.define.{Discover, ExternalModule}
import mill.eval.Evaluator
import mill.scalalib._
import ujson._
import mill.define.Task

object StewardPlugin extends ExternalModule {

Expand All @@ -43,20 +44,36 @@ object StewardPlugin extends ExternalModule {
def findModules(ev: Evaluator) =
ev.rootModule.millInternal.modules.collect { case j: JavaModule => j }

def toModuleDep(m: JavaModule) = {
val artifactMods = m match {
case scalaMod: ScalaModule =>
T.task(
Some(
(scalaMod.artifactScalaVersion(), scalaMod.scalaVersion(), scalaMod.platformSuffix())
)
)
case _ => T.task(None)
def toModuleDep(m: JavaModule): Task[ModuleDependencies] = {

// We also want to use mandatoryIvyDeps, but that`s too new, so we hardcode any scala lib here
val mandatoryIvyDeps = m match {
case s: ScalaModule => s.scalaLibraryIvyDeps
case _ => T.task { Agg.empty[Dep] }
}

val dependencies = T.task {
val ivy = m.ivyDeps()
val mod = artifactMods()
ivy.iterator.toSeq.map(Dependency.fromDep(_, mod))

val convert = m.resolveCoursierDependency()

val ivy = m.ivyDeps() ++ mandatoryIvyDeps() ++ m.compileIvyDeps() ++ m.runIvyDeps()

ivy.toSeq.map { dep =>
val resolveName = convert(dep).module.name.value

val artifactId = ArtifactId(
dep.dep.module.name.value,
if (resolveName != dep.dep.module.name.value)
Option(resolveName)
else None
)

Dependency(
dep.dep.module.organization.value,
artifactId,
dep.dep.version
)
}
}

T.task {
Expand Down

0 comments on commit 8ec1321

Please sign in to comment.