Debugging Exec tasks is painful if you don’t know the command line being executed. But the only way I have found to see the command line is to run “gradle --debug”, which swamps the information you need in a sea of uninteresting debug output.
So is there an easy way to have Gradle print the command being executed just before it runs? I want roughly the same behaviour as Make or SCons – nothing wrong with telling me the name of the task being executed, but I need to know the command line.
That’s pretty close to what I want, except it prints the command line for every Exec task, regardless of whether it is run or not in a particular build. I only want to see commands that are actually executed in this build.
Are you sure? beforeExecute is supposed to only get called for tasks that are about to be executed.
Another way is to add an action to all exec tasks. This could be done from a build script or a build listener in init.gradle and would roughly look like this:
Are you sure? beforeExecute is supposed to only get called for tasks that are about to be executed.
Yes, quite sure. I just tried this again in a different project with a completely different build script, and I’m getting the same result: TaskExecutionListener.beforeExecute() is being called for every task, regardless of whether they need to be run or not.
Demonstration. First, here is my build output without any init script:
A task that reports up-to-date is being executed. You can additionally check task.didWork, but only after the task has executed.
Darn. All I want is the feature that Make has had for 30+ years.
Your second suggestion, of tacking a doFirst() onto every task, works fine. (Of course it doesn’t apply to Java compilation tasks, but I presume that is because Gradle isn’t actually spawning javac in a separate process, so there is no command line to print.)
If my suggestion works, isn’t that case solved? You can’t have this feature for all tasks because not all tasks fork a new process (actually most don’t), hence there is no command line to print.