Repository navigation
Named RootModule in Mill 1.x #7278
Replies: 4 comments 3 replies
This comment was marked as spam.
This comment was marked as spam.
|
The root module is intentionally anonymous in Mill, so The usual workaround is to make the name an explicit part of your reusable trait’s API, and optionally default it from import mill.*
trait MyExtensionModule extends Module {
def artifactName: T[String] = Task {
moduleSegments.parts.lastOption.getOrElse(
sys.error("artifactName must be overridden for the root module")
)
}
def xmlFile = Task.Source(moduleDir / s"${artifactName()}.xml")
def assetDir = Task.Source(moduleDir / artifactName())
def validateArtifacts = Task {
val xml = xmlFile().path
val dir = assetDir().path
if (!os.exists(xml)) sys.error(s"Missing $xml")
if (!os.isDir(dir)) sys.error(s"Missing directory $dir")
}
}
object `package` extends RootModule with MyExtensionModule {
override def artifactName = Task { "MyName" }
def myTask = Task {
validateArtifacts()
// copy/do whatever
}
} |
|
Thank you for the answer, @VectorPeak. This is the approach I am using. |
|
It was a long time ago, but for Mill 0.11.x, we could do this: import mill._
object MyName extends RootModule {
val name = millOuterCtx.segment match {
case define.Segment.Label(s) => s
case _ => ???
}
def hello = T { s"Hello, $name" }
}And get this: In my case: import mill._
trait ExtensionModule extends RootModule {
def extensionName = millOuterCtx.segment match {
case define.Segment.Label(s) => s
case _ => ???
}
def sourceDir: os.Path = millSourcePath / "src"
def targetDir: T[os.Path]
def extensionFolder = T.source { sourceDir / extensionName }
def extensionXmlFile = T.source { sourceDir / s"$extensionName.xml" }
def validateExtensionXml() = Task.Command { ... }
def deploy() = Task.Command { ... }
}
object MyName extends ExtensionModule {
def targetDir = os.Path( ... )
} |
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
I’m using Mill 1.1.5 to automate a workflow for some configuration files within a flat project structure where there is no notion of submodules. To keep terminal invocation commands short (allowing users to run
mill my-taskdirectly), I am using the standardobject `package` extends Modulesyntax in mybuild.millfile.The setup of the project structure requires a
MyName.xmlfile and a correspondingMyNameasset folder to sit side by side inside the application directory.I would like to share a reusable trait (say
MyExtensionModule) across different build setups to validate and copy these artifacts automatically from the development folder to the application one. If the module could be explicitly named (likeobject MyName extends MyExtensionModule), I would simply querymoduleSegments.parts.lastinside the trait to discover the string token"MyName"and dynamically find the paths.Is there a recommended idiom or clean workaround in Mill 1.x to have a named package extending
RootModule?All reactions