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.