Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give more control over module dependencies #955

Merged
merged 2 commits into from
Sep 8, 2020
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
14 changes: 7 additions & 7 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class BloopImpl(ev: () => Evaluator, wd: Path) extends ExternalModule { outer =>
val bloopResolution: Task[BloopConfig.Resolution] = T.task {
val repos = module.repositories
val allIvyDeps = module
.transitiveIvyDeps() ++ scalaLibraryIvyDeps() ++ module.compileIvyDeps()
.transitiveIvyDeps() ++ scalaLibraryIvyDeps() ++ module.transitiveCompileIvyDeps()
val coursierDeps =
allIvyDeps.map(module.resolveCoursierDependency()).toList
BloopConfig.Resolution(artifacts(repos, coursierDeps))
Expand All @@ -371,13 +371,13 @@ class BloopImpl(ev: () => Evaluator, wd: Path) extends ExternalModule { outer =>
case _ => T.task(Loose.Agg.empty[Dep])
}

val ivyDepsClasspath =
module
.resolveDeps(T.task {
module.compileIvyDeps() ++ module
.transitiveIvyDeps() ++ scalaLibIvyDeps()
val ivyDepsClasspath = module
.resolveDeps(T.task {
module.transitiveCompileIvyDeps() ++
module.transitiveIvyDeps() ++
scalaLibIvyDeps()
})
.map(_.map(_.path).toSeq)
.map(_.map(_.path).toSeq)

def transitiveClasspath(m: JavaModule): Task[Seq[Path]] = T.task {
m.moduleDeps.map(classes) ++
Expand Down
2 changes: 1 addition & 1 deletion contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class MillBuildServer(evaluator: Evaluator, bspVersion: String, serverVersion: S
val module = getModule(targetId, modules)
val sources = evaluateInformativeTask(
evaluator,
module.resolveDeps(T.task(module.compileIvyDeps() ++ module.transitiveIvyDeps()), sources = true),
module.resolveDeps(T.task(module.transitiveCompileIvyDeps() ++ module.transitiveIvyDeps()), sources = true),
Agg.empty[PathRef]
)
val unmanaged = evaluateInformativeTask(
Expand Down
2 changes: 1 addition & 1 deletion contrib/scalapblib/src/ScalaPBModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ trait ScalaPBModule extends ScalaModule {
def scalaPBIncludePath: T[Seq[PathRef]] = T.sources { Seq.empty[PathRef] }

def scalaPBProtoClasspath: T[Agg[PathRef]] = T {
resolveDeps(T.task { compileIvyDeps() ++ transitiveIvyDeps() })()
resolveDeps(T.task { transitiveCompileIvyDeps() ++ transitiveIvyDeps() })()
}

def scalaPBUnpackProto: T[PathRef] = T {
Expand Down
1 change: 1 addition & 0 deletions contrib/scoverage/src/ScoverageModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
override def generatedSources: Target[Seq[PathRef]] = T{ outer.generatedSources() }
override def allSources: Target[Seq[PathRef]] = T{ outer.allSources() }
override def moduleDeps: Seq[JavaModule] = outer.moduleDeps
override def compileModuleDeps: Seq[JavaModule] = outer.compileModuleDeps
override def sources: Sources = T.sources { outer.sources() }
override def resources: Sources = T.sources { outer.resources() }
override def scalaVersion = T{ outer.scalaVersion() }
Expand Down
2 changes: 1 addition & 1 deletion contrib/tut/src/TutModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ trait TutModule extends ScalaModule {
Lib.resolveDependencies(
repositories :+ MavenRepository(s"https://dl.bintray.com/tpolecat/maven"),
Lib.depToDependency(_, scalaVersion()),
compileIvyDeps() ++ transitiveIvyDeps() ++ Seq(
transitiveCompileIvyDeps() ++ transitiveIvyDeps() ++ Seq(
ivy"org.tpolecat::tut-core:${tutVersion()}"
)
)
Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ case class GenIdeaImpl(evaluator: Evaluator,
case x: ScalaModule => x.scalaLibraryIvyDeps
case _ => T.task{Loose.Agg.empty[Dep]}
}
val allIvyDeps = T.task{mod.transitiveIvyDeps() ++ scalaLibraryIvyDeps() ++ mod.compileIvyDeps()}
val allIvyDeps = T.task{mod.transitiveIvyDeps() ++ scalaLibraryIvyDeps() ++ mod.transitiveCompileIvyDeps()}

val scalaCompilerClasspath = mod match{
case x: ScalaModule => x.scalaCompilerClasspath
Expand Down
36 changes: 31 additions & 5 deletions scalalib/src/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ trait JavaModule extends mill.Module
/** The direct dependencies of this module */
def moduleDeps = Seq.empty[JavaModule]

/** The compile-only direct dependencies of this module. */
def compileModuleDeps = Seq.empty[JavaModule]

/** The compile-only transitive ivy dependencies of this module and all it's upstream compile-only modules. */
def transitiveCompileIvyDeps: T[Agg[Dep]] = T{
// We never include compile-only dependencies transitively, but we must include normal transitive dependencies!
compileIvyDeps() ++ T.traverse(compileModuleDeps)(_.transitiveIvyDeps)().flatten
}

/**
* Show the module dependencies.
* @param recursive If `true` include all recursive module dependencies, else only show direct dependencies.
*/
def showModuleDeps(recursive: Boolean = false) = T.command {
val normalDeps = if (recursive) recursiveModuleDeps else moduleDeps
val compileDeps = if(recursive) compileModuleDeps.flatMap(_.transitiveModuleDeps).distinct else compileModuleDeps
val deps = (normalDeps ++ compileDeps).distinct
val asString = s"${if(recursive) "Recursive module" else "Module"} dependencies of ${millModuleSegments.render}:\n\t${
deps.map { dep =>
dep.millModuleSegments.render ++
(if (compileModuleDeps.contains(dep) || !normalDeps.contains(dep)) " (compile)" else "")
}.mkString("\n\t")
}"
T.log.outputStream.println(asString)
}

/** The direct and indirect dependencies of this module */
def recursiveModuleDeps: Seq[JavaModule] = {
moduleDeps.flatMap(_.transitiveModuleDeps).distinct
Expand Down Expand Up @@ -123,14 +149,14 @@ trait JavaModule extends mill.Module
* The upstream compilation output of all this module's upstream modules
*/
def upstreamCompileOutput = T{
T.traverse(recursiveModuleDeps)(_.compile)
T.traverse((recursiveModuleDeps ++ compileModuleDeps.flatMap(_.transitiveModuleDeps)).distinct)(_.compile)
}

/**
* The transitive version of `localClasspath`
*/
def transitiveLocalClasspath: T[Agg[PathRef]] = T{
T.traverse(moduleDeps)(m =>
T.traverse(moduleDeps ++ compileModuleDeps)(m =>
T.task{m.localClasspath() ++ m.transitiveLocalClasspath()}
)().flatten
}
Expand Down Expand Up @@ -229,7 +255,7 @@ trait JavaModule extends mill.Module
}

def resolvedIvyDeps: T[Agg[PathRef]] = T {
resolveDeps(T.task{compileIvyDeps() ++ transitiveIvyDeps()})()
resolveDeps(T.task{transitiveCompileIvyDeps() ++ transitiveIvyDeps()})()
}

/**
Expand Down Expand Up @@ -425,10 +451,10 @@ trait JavaModule extends mill.Module
def ivyDepsTree(inverse: Boolean = false, withCompile: Boolean = false, withRuntime: Boolean = false): Command[Unit] =
(withCompile, withRuntime) match {
case (true, true) => T.command {
printDepsTree(inverse, T.task{ compileIvyDeps() ++ runIvyDeps() })
printDepsTree(inverse, T.task{ transitiveCompileIvyDeps() ++ runIvyDeps() })
}
case (true, false) => T.command {
printDepsTree(inverse, compileIvyDeps)
printDepsTree(inverse, transitiveCompileIvyDeps)
}
case (false, true) => T.command {
printDepsTree(inverse, runIvyDeps)
Expand Down
7 changes: 6 additions & 1 deletion scalalib/src/PublishModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ trait PublishModule extends JavaModule { outer =>
.map(_.copy(scope = Scope.Provided))

val modulePomDeps = T.sequence(moduleDeps.map(_.publishSelfDependency))()
val compileModulePomDeps = T.sequence(compileModuleDeps.collect {
case m: PublishModule => m.publishSelfDependency
})()

ivyPomDeps ++ compileIvyPomDeps ++ modulePomDeps.map(Dependency(_, Scope.Compile))
ivyPomDeps ++ compileIvyPomDeps ++
modulePomDeps.map(Dependency(_, Scope.Compile)) ++
compileModulePomDeps.map(Dependency(_, Scope.Provided))
}

def pom: Target[PathRef] = T {
Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ trait ScalaModule extends JavaModule { outer =>
}

override def resolvedIvyDeps: T[Agg[PathRef]] = T {
resolveDeps(T.task{compileIvyDeps() ++ scalaLibraryIvyDeps() ++ transitiveIvyDeps()})()
resolveDeps(T.task{transitiveCompileIvyDeps() ++ scalaLibraryIvyDeps() ++ transitiveIvyDeps()})()
}

override def resolvedRunIvyDeps: T[Agg[PathRef]] = T {
Expand Down