是否可以创建一个 Apache Ant build.xml,它可以在一个目标中创建任务并随后在另一个目标中使用它?
这是一个简单build.xml
的说明:
<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>
我得到的输出是:
Buildfile: /path/to/build.xml
BUILD FAILED
/path/to/build.xml:5: taskdef class org.example.TestTask cannot be found
using the classloader AntClassLoader[]
是否可以在不使用嵌套 Ant 执行的情况下将其作为一个步骤来完成?我正在分别解决这个问题,首先注释<taskdef>
,明确构建compile-task
目标,取消注释<taskdef>
,最后构建use-task
目标。