mustRunAfter does not work for exec type tasks

(I. D.) #1

I am using external tooling for javascript processing, which leaves some temp files I want to delete afterwards.

The following does not work:

task compileJS(type: Exec) {
    commandLine 'cmd', '/c', 'r.js.cmd -o build.js'
  task cleanTempJS(type: Delete) {
    delete fileTree(dir: "$webAppDirName/js/comp")
    delete "$webAppDirName/js/comp"
  cleanTempJS.mustRunAfter compileJS
war.dependsOn compileJS
war.dependsOn cleanTempJS

I had to switch to direct dependency (cleanTempJS.dependsOn compileJS) which works as expected, but is semantically wrong.

Gradle version 2.2

(Luke Daley) #2

You don’t say how it didn’t work.

Regardless, I’d be inclined to implement this as a ‘doLast {}’ on the ‘compileJS’ task. You can use the ‘project.delete’ method.

(I. D.) #3

Cleanup task was run before compile task finished, (but after it started) resulting in errors both from external compliler and gradle. In other words, both compileJS and cleanTempJS were run in parallel.

I cannot seem to reproduce it now - to the point of build working without both the dependency and mustRunAfter (!), which probably means “reliably works by pure chance”. I’m afraid I have no knowledge of gradle internals to assume why.

You are certainly right with doLast thing, I’ll do that. That was my lack of knowledge of gradle API. Thank you.