Apologies if this is an obvious n00b question and I’ve just failed to find the answer.
I have a custom task:
task myTask(type: MyType, dependsOn: [ "build1", "build2" ]) {
inputs.file "build1/dep.file"
inputs.file "build2/dep.file"
myOption "build1/dep.file build2/dep.file"
}
This is fine, works like a charm.
But I realize that as I add dependencies, I have to update the input files and my option; that seems like an opportunity for error. So, I try to do it programatically:
task myTask(type: MyType, dependsOn: [ "build1", "build2" ]) {
FileTree tree = fileTree(dir: ".").include("**/dep.file")
String files = ""
tree.each { file ->
files = files + file.getAbsolutePath()
}
inputs.files tree
myOption files
}
This doesn’t work because the tree is apparently constructed at configuration time and not at execution time. Use doFirst?
task myTask(type: MyType, dependsOn: [ "build1", "build2" ]) {
FileTree tree = null
String files = ""
doFirst {
tree = fileTree(dir: ".").include("**/dep.file")
tree.each { file ->
files = files + file.getAbsolutePath()
}
}
inputs.files tree
myOption files
}
Nope: NPE on tree. Move everything inside doFirst? Nope, then the task doesn’t see the options.
Am I overlooking the obvous?