Is it possible to create an Apache Ant build.xml that can create a task in one target and subsequently use it in another target?
Here is a simple build.xml
to illustrate this:
<project name="BuildAndUseTask" default="use-task">
<!-- Define the task -->
<taskdef name="testtask"
classname="org.example.TestTask"/>
<!-- Compile the task -->
<target name="compile-task">
<javac srcdir="task/src" destdir="."/>
</target>
<!-- Use the task -->
<target name="use-task" depends="compile-task">
<testtask option="something"/>
</target>
</project>
The output I get is:
Buildfile: /path/to/build.xml
BUILD FAILED
/path/to/build.xml:5: taskdef class org.example.TestTask cannot be found
using the classloader AntClassLoader[]
Is this possible to do this as a single step without resorting to using nested Ant executions? I am working around this separately by first commenting the <taskdef>
, explicitly building the compile-task
target, uncommenting the <taskdef>
, and finally build the use-task
target.