I need to programatically clear the UP-TO-DATE property for gradle task dependencies. I am working in a subproject build.gradle file that handles the integration of other subprojects and deploys them. I need to be able to clear the property only if one specific task is running. I want to ensure that three of my tasks (clean, cleanNodeJs, and npmInstall) are always rerun prior to starting my deployment task. However, I don't want to affect other tasks where it is acceptable for it to not rerun those things (especially since npmInstall takes a non-trivial amount of time to run).
I looked at this similar question but the answers there do not work for me. Using --rerun-tasks doesn't suffice because it's dependent upon the caller to specify and I need to ensure that my required tasks are always rerun for this deployment task. Setting outputs.upToDateWhen { false } for those three tasks isn't what I'm looking for either as that would then require those tasks to always rerun even for other tasks that don't need them to (unless there's a way to specify that just within my deployment task?). I tried the 3rd suggested answer within the build.gradle file by prepending clean in my dependsOn (i.e. dependsOn(cleanClean) but that threw an error for an unrecognized task. Perhaps the fourth answer could work but I'm not sure I understand it.
I did try setting my deployment task to depend on the three aforementioned tasks and then specifying that each one must run after the appropriate one (see below) but that doesn't seem to help.
task deploy() {
dependsOn(clean, cleanNodeJs, npmInstall)
// my deployment logic
}
cleanNodeJs.mustRunAfter(clean)
npmInstall.mustRunAfter(cleanNodeJs)
deploy.mustRunAfter(npmInstall)
Hopefully what I'm trying to do is possible. Thanks in advance for your time and help!