答案 0 :(得分:4)
根据Mark O'Connor在问题评论中的暗示,我提出了以下解决方案:
<project name="cwd" default="parent">
<target name="parent">
<echo message="Current working directory in parent: ${basedir}" />
<ant antfile="../build.xml" dir="subdir" target="subDirTarget"
inheritAll="true" inheritRefs="true" />
</target>
<target name="subDirTarget">
<echo message="Current working directory in subDirTarget: ${basedir}" />
</target>
</project>
这有效 - 输出:
Buildfile: C:\Sandbox\parent\build.xml
parent:
[echo] Current working directory in parent: E:\Sandbox\parent
subDirTarget:
[echo] Current working directory in subDirTarget: E:\Sandbox\parent\subdir
BUILD SUCCESSFUL
Total time: 1 second
我还尝试使用Ant-Contrib的<var>
任务来更改basedir
,但这似乎没有效果。