The code below throws the following error: import only allowed as a top-level task
<target name="packfiles">
<if>
<equals arg1="${pack.type}" arg2="impl1" />
<then>
<import as="packimpl" file="myImplementation1.xml">
</then>
<else>
<import as="packimpl" file="myImplementation2.xml">
</else>
</if>
<antcall target="packimpl.build" />
</target>
<ac:if> <isset property="some_property_is_set" /> <then> <import file="file1.xml" /> </then> </ac:if>
Try the above before you start declaring the targets
"On execution it will select the proper ProjectHelper to parse the imported file, using the same algorithm as the one executed at startup. The selected ProjectHelper instance will then be responsible to actually parse the imported file"
Source: http://ant.apache.org/manual/Tasks/import.html
The task documentation explicitly mentions this:
To solve it, simply move the import outside the target.