I'm trying to run an exec task only if a file has been updated since the last build. My initial attempt looked like this:
task generateLocalizedStrings(type:Exec) {
ext.srcFile = file('../../../localization/language-files/en_US/wdmobilestringres.properties')
ext.destDir = new File("src/main/res")
inputs.file srcFile
outputs.dir destDir
doLast {
println "Executing localization script"
workingDir '../../../localization/'
commandLine 'python', 'localizationScript.py'
}
}
However, this fails with "execCommand == null!"
I found a workaround but I'd really prefer a proper solution.
task generateLocalizedStrings(type:Exec) {
ext.srcFile = file('../../../localization/language-files/en_US/wdmobilestringres.properties')
ext.destDir = new File("src/main/res")
inputs.file srcFile
outputs.dir destDir
workingDir '../../../localization/'
commandLine 'python', 'dummyScript.py'
doLast {
println "Executing localization script"
workingDir '../../../localization/'
commandLine 'python', 'localizationScript.py'
}
}
One option is to make the task a generic task and to explicitly call the exec
dsl. E.g. from this:
task("MyTask", type: Exec) {
doLast {
commandLine "your commandline"
}
}
to this
task("MyTask") {
doLast {
exec {
commandLine "your commandline"
}
}
}
You need to get rid of the doLast
block, and instead configure workingDir
and commandLine
outside that block. (Configuring a task after it has run is too late.)
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