-
Given the following directory structure, I set up immediate subdirectories as dynamic cross modules.
build.mill package build
import mill._, scalalib._, scalafmt._
import $packages._
import $file.{versions => v}
def isSbtProject(p: os.Path) = os.exists(p / "build.sbt")
def moduleNames = interp.watchValue(
os.walk(millSourcePath, !isSbtProject(_), maxDepth = 1)
.map(_.last)
)
object modules extends Cross[MyModule](moduleNames)
trait MyModule extends SbtModule with Cross.Module[String] with ScalafmtModule {
outer =>
val scalaVersion = v.scalaVersion
// Ends with 'modules' that need to be removed
def millSourcePath = super.millSourcePath / os.up / crossValue
def scalacOptions: T[Seq[String]] = Seq(
"-encoding", "UTF-8",
"-feature",
"-Werror",
"-explain",
"-deprecation",
"-unchecked",
"-Wunused:all",
"-rewrite",
"-indent",
"-source", "future",
)
object test extends SbtTests with TestModule.ScalaTest {
def scalacOptions: T[Seq[String]] = Seq("-encoding", "UTF-8")
val commonDeps = Seq(ivy"org.scalatest::scalatest:${v.scalatestVersion}")
val scDeps = Seq(ivy"org.scalatestplus::scalacheck-1-18:${v.scalacheckVersion}")
// Alternatively, separate this logic out.
// https://mill-build.org/mill/scalalib/build-examples.html
def ivyDeps = Task{commonDeps ++ (if (crossValue == "simple-linked-list") scDeps else Seq())}
}
} As you can see towards the end, one of the modules gets an additional dependency added depending on its name. This is ok for now, but if more and more modules need special configuration, the root build file will become messy. My question is, can a module-level |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
No, module-level If you are finding a lot of modules needing special configuration, then instead of using a cross module you can use normal modules and traits to extract out the commonalities. That would let you more easily mix and max things, e.g. having each module inherit different sets of traits, or easily adding overrides specific to each specific module |
Beta Was this translation helpful? Give feedback.
No, module-level
package.mill
s always translate into normalModule
s, notCross
modules. And modules can only be defined in one place, so if it's defined inbuild.mill
it cannot be defined in a nestedpackage.mill
, and vice versaIf you are finding a lot of modules needing special configuration, then instead of using a cross module you can use normal modules and traits to extract out the commonalities. That would let you more easily mix and max things, e.g. having each module inherit different sets of traits, or easily adding overrides specific to each specific module