Skip to content

Instantly share code, notes, and snippets.

@megri
Last active May 10, 2024 11:41
Show Gist options
  • Save megri/7b8dc1bf02b15bf44990f04da2a6da6f to your computer and use it in GitHub Desktop.
Save megri/7b8dc1bf02b15bf44990f04da2a6da6f to your computer and use it in GitHub Desktop.
Scala cli-style inline deps declarations for mill
import mill._, scalalib._
object MyModule extends ScalaModule {
def inlineIvyDeps = T {
def parseDep(usingDepClause: String): Dep = {
val part = usingDepClause.drop("//> using dep ".size)
if (part.startsWith("\"")) Dep.parse(part.tail.init.trim)
else Dep.parse(part.trim)
}
val deps = for {
sourceRoot <- geny.Generator(sources()).flatten
scalaFile <- os.walk.stream(sourceRoot.path).filter(path => os.isFile(path) && path.ext == "scala")
usingDep <- os.read.lines.stream(scalaFile).filter(line => line.startsWith("//> using dep"))
} yield parseDep(usingDep)
Agg.from(deps.toList)
}
def ivyDeps = inlineIvyDeps()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment