我有两个蚂蚁文件:
1)主文件
Run Code Online (Sandbox Code Playgroud)<include file="otherFile.xml" as="otherFile"/> <target name="firstTarget"> <antcall target="otherFile.secondTarget"/> </target>
2)实用程序文件
<target name="secondTarget">
<antcall target="thirdTarget"/>
</target>
<target name="thirdTarget">
<echo message="ok"/>
</target>
Run Code Online (Sandbox Code Playgroud)
当我调用firstTarget
它说它找不到thirdTarget
.如果我改变secondTarget
这种方式:
Run Code Online (Sandbox Code Playgroud)<target name="secondTarget"> <antcall target="otherFile.thirdTarget"/> </target>
然后它工作.但是我不能直接使用secondTarget.因为第二个文件没有创建前缀otherFile
ANT 文档说:
对于每个包含的文件,Ant 添加一个属性,其中包含包含的构建文件的路径。通过此路径,包含的构建文件可以保留资源并能够相对于其位置引用它们。因此,如果我包含一个名为 builddocs 的 docsbuild.xml 文件,我可以将其路径获取为 ant.file.builddocs,类似于主构建文件的 ant.file 属性。
您可以利用它来做您想做的事情,即使 antcall 工作,无论它是从“包含”上下文还是顶级上下文调用。您应该做的是将 otherFile.context 属性的值设置为“otherFile”。如果定义了 ant.file.otherFile 属性,如果没有定义则为 '' (即空字符串)。然后你可以使用属性扩展来调用目标;例如:
<antcall target="${otherFile.context}thirdTarget"/>
Run Code Online (Sandbox Code Playgroud)
还没有尝试过,但我认为没有理由它不起作用。