Debugging ant tasks is not as simple as plain old java debugging.
While you can debug an Ant file adding breakpoints, digging inside the
code of specific custom task will require you to add a remote debugger
in order to be able to "catch" the running process.
I will explain how to do this in Eclipse, altough I recon it can be
achieved with all major java IDEs. First thing is to create a new run
configuration for the ant file where you plan to use your customized
new task. To do so, go to:
Run -> External Tools -> External Tools configuration...
Right click in Ant Build -> New and in the Main tab select your ant
script in Buildfile field. Then go to JRE tab and insert the following
JVM arguments:
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
If you wonder what these arguments mean check this, although a bit
updated (Java 1.5) still works.
Once this is done, you must create a new Debug configuration for a
remote Java application. To do so, navigate to:
Run-> Debug configurations
Drop down the list in the left column and right click in Remote Java
Application -> New. Select the project name in the Project field.
Default values for host and port are okay as long as you used the same
ones for the Ant configuration (JVM arguments).
Everything is ready for the test run! Add breakpoints wherever you
consider necessary. In my case, I added one both in the ant script
that uses the custom ant task as well as in the custom ant task, in
the execute method.
Right click in your ant script or task -> Debug As...-> Ant >Build
first
Now BEFORE calling your custom ant task code, go to Run-> Debug
Configurations and debug your previously created Java Remote
Application config. This will start a separate thread that will debug
your custom ant task code, provided that you included some breakpoints
:) You can see in the following image how in my case, thread stopped
in the execute method of my custom ant task.
After this point, it is up to you to decide what to do next...