如何修复仅允许作为顶级任务的 Ant 导入? [英] How to fix Ant import which is only allowed as a top-level task?

查看:25
本文介绍了如何修复仅允许作为顶级任务的 Ant 导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码抛出以下错误:import only allowed as a top-level task

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>

推荐答案

任务文档 明确提到这一点:

The task documentation explicitly mentions this:

导入任务只能用作顶级任务.这意味着它不能用于目标.

The import task may only be used as a top-level task. This means that it may not be used in a target.

要解决它,只需将导入移到目标之外.

To solve it, simply move the import outside the target.

<project ...>

   ...

   <if>
       <equals arg1="${pack.type}" arg2="impl1" />
       <then>
           <import as="packimpl" file="myImplementation1.xml">
       </then>
       <else>
            <import as="packimpl" file="myImplementation2.xml">
       </else>
   </if>


   <target name="packfiles">        
      <antcall target="packimpl.build" />
   </target>

   ...

</project>

这篇关于如何修复仅允许作为顶级任务的 Ant 导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆