I have several tasks that require a sub-directory of build to exist.
What is the best way to achieve this?
So far I have this:
afterEvaluate {
mkdir "$buildDir/work"
}
And this:
task prepareDirs {
mkdir "$buildDir/test"
}
The second one works because it is run in the configuration phase and so I don't need to put dependsOn on all the tasks that require it.
mkdir even the right way to do it?buildDir created? Can I extend that task?EDIT: I noticed that both of these fail if I chain the clean task on the command line before my main tasks.
The following should work. Note that prepareDirs must have constraint mustRunAfter clean, to solve the issue you mentioned in your EDIT
// task responsible to create the tmp/work dir
task prepareDirs {
mustRunAfter clean
doLast {
mkdir "$buildDir/work"
}
}
// make all tasks depend on the prepareDirs task
// exept 'clean' and 'prepareDirs' (avoid circular dependency)
tasks.each {
if (it != prepareDirs && it != clean) {
it.dependsOn prepareDirs
}
}
If you don't have much tasks that require the build/work dir and don't want to make all tasks depend on you prepareDirs task, you can do that :
[myTask1, myTask2, myTask3].each {
it.dependsOn prepareDirs
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With