-
-
Notifications
You must be signed in to change notification settings - Fork 419
Description
Current documentation: https://mill-build.org/mill/fundamentals/tasks.html#_anonymous_tasks
You can define anonymous tasks using the Task.Anon {...} syntax. These are not runnable from the command-line, but can be used to share common code you find yourself repeating in Tasks and Commands.
Anonymous task’s output does not need to be JSON-serializable, their output is not cached, and they can be defined with or without arguments. Unlike Tasks or Commands, anonymous tasks can be defined anywhere and passed around any way you want, until you finally make use of them within a downstream task or command.
From this description, it is not clear why this does not work
def taskA = Task {
val a = 1+2
taskB(a)() // instead, doing taskB(1+2)() does work. taskB(taskC())() also does not work.
}
def taskB(n: Int) = Task.Anon {
println(Task.dest) // prints taskA.dest as expected, if there is no compilation error
println(n)
}
def taskC = Task{
1 + 2
}
results in error
Task#apply() call cannot use
val a defined within the Task{...} block
It seems like this limitation somehow defeats the purpose of Anonymous tasks as helper functions for reusable pieces of code, as it's too limiting to not use any locally defined variables. This leads to a lot of code duplication, because there doesn't seem to be a good way to split a Task
into smaller pieces. It would be great if Anon task can be updated to reflect this, and also to document what the best practices are for splitting Tasks up into smaller ones when the logic is not trivial.