I made it work, but I don’t understand how or why just yet. I think it has to do with creation rules vs. mutation rules. At first I had:
model {
components {
juiceComponent(JuiceComponent) {
binaries {
juice(JuicerBinarySpec) { // This is a creation rule
args = ['a', 'b']
}
}
}
}
}
And this code:
@BinaryTasks
void generateTasks(ModelMap<Task> tasks, final JuiceBinarySpec binary) {
tasks.create("${binary.name}Juicer", JuicerTask) { task ->
task.args = binary.getArgs()
}
}
Would give me the not mutable exception (Cannot set value for model element ‘components.juiceComponent.binaries.juicer.args’ as this element is not mutable.).
But after I changed the creation rule to a mutation rule in the DSL like so:
model {
components {
juiceComponent(JuiceComponent) {
binaries {
juicer { // This is now a mutation rule
args = ['a', 'b']
}
}
}
}
}
Then the exception went away. So now I wonder, how do I assign values to task inputs when a creation rule is used?