This is pretty messy, but it works. Ant is actually pretty easy to script, and if you use at least Java 6 (or it could be Java 7), javascript support is built-in and therefore can be used right out of the box. This defines a task that will reflect the dependencies of any goal in the order of the call:
<scriptdef name="listdepends" language="javascript"> <attribute name="target"/> <![CDATA[ var done = []; var echo = project.createTask("echo") function listdepend(t) { done.push(t.getName()); var depends = t.getDependencies(); while (depends.hasMoreElements()) { var t2 = depends.nextElement(); if (done.indexOf(t2)==-1) listdepend(project.getTargets().get(t2)); } echo.setMessage(t.getName()); echo.perform(); } var t = attributes.get("target"); if (t!=null) { var targ = project.getTargets().get(t); listdepend(targ); } ]]> </scriptdef>
In your case, you can create a new target (or not) and call it like this:
<target name="listfoo"> <listdepends target="foo"/> </target>
As I said, this is somewhat messy. This is probably not very fast (although if your target is not causing thousands of others, it is probably not noticeably slow). It will not process antcall tasks (although it can be changed so easily) or respond to if and except attributes. If the dependencies are too far away, this can lead to a limitation of the depth of the recursion (but I doubt that any project has them deeply embedded).
An array is used to make sure that each dependency is specified once (ant will only run them once).
source share