How to always execute a task after another task?

What is the official way (if one) to make one task always execute after another task? This is different than both dependsOn and mustRunAfter.

In my build we use JDK 7, but we target JDK 6. Rather than needing to have users configure the second JDK path (in order to set “bootstrap class path”) we opted to use a library called Animal Sniffer that checks API usages. So my build defines a task named checkJavaApiSignature.

In terms of ordering: * checkJavaApiSignature depends on compileJava : compileJava has to be run before checkJavaApiSignature * checkJavaApiSignature needs to be run everytime compileJava has been run, every time compileJava has been run. But this is the one that Gradle (iiuc) does not really have a task relationship for. To my understanding, mustRunAfter is more about specifying which task to run when both are requested.

I tried using doLast but that did not work. Neither:

compileJava.doLast checkJavaApiSignature

^^ config error

compileJava.doLast {checkJavaApiSignature}

^^ nothing happens

compileJava.doLast {checkJavaApiSignature.execute()}

^^ error because checkJavaApiSignature’s deps arent run

If you are on Gradle 1.7 you could use a finalizer task.

compileJava.finalizedBy checkJavaApiSignature
1 Like

Now I may have to :slight_smile:

“Finalizer task will be executed even if the finalized task fails.” Not ideal, but its better than nothing. Any plans to add support for the exact semantic I am looking for? Seems like it would be a pretty standard requirment. Since in my case, Animal Sniffer is just called through ant I could probably just move all that code into a doLast block and be done with it, but the doLast approach is not always viable.

1 Like