Ant<import>与<包括>任务 [英] Ant <import> vs. <include> tasks

查看:28
本文介绍了Ant<import>与<包括>任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在看到 Ant 有一个 任务和一个 任务.

I now see Ant has both an <include> task and an <import> task.

根据描述:

在当前项目中包含另一个构建文件.

Include

Include another build file into the current project.

将另一个构建文件导入当前项目.

Import

Imports another build file into the current project.

那么,为什么要使用一个?

So, why use one over the other?

这是我的实际问题:

在我们当前的构建系统中,我们将一堆 JavaScript 连接起来,然后将它们最小化.JavaScript 位于十几个不同的目录中,我们从每个目录中提取批次并将它们连接成五六个超级最小化的 JavaScript.其中一些文件被复制到多个超级 JavaScript 中.

In our current build system, we are concatenating a bunch of JavaScripts and then minimizing them. The JavaScripts are located in a dozen different directories, and we are taking batches from each directory and concatenating them into five or six super minimized JavaScripts. Some of these files are copied into multiple super JavaScripts.

为了使调试更容易,构建更灵活,我想将所有文件复制到 target/work/resources2 目录中,其中的每个子目录代表一个不同的超级最小化 JavaScript.出于调试目的,我们将包括非最小化的超级 JavaScript 和原始版本.构建脚本并不复杂,但整个部分占用了很多行.我想把 的东西放到一个单独的 XML 文件中,所以整个事情看起来像这样:

In order to make debugging easier, and the build a bit more flexible, I want to copy all of the files into the target/work/resources2 directory with each sub-directory under there representing a different super minimized JavaScript. For debugging purposes, we'll include the non-minimized super JavaScript and the originals. The build script isn't complex, but the whole section is taking up a lot of lines. I was thinking of putting the <copy> stuff into a separate XML file, so the whole thing looks like this:

<target name="process-resources"
     description="Concatenate and minimize the JavaScripts (using Maven lifecycle names for our targets">
     <!-- The following include the copying stuff -->
     <here.be.dragons file="${basedir}/reservations.xml"/>
     <here.be.dragons file="${basedir}/date.xml"/>
     <here.be.dragons file="${basedir}/select.xml"/>

     <for param="concat.dir">
         <fileset dir="${work.dir]/resources2"/>
         <sequential>
            <here.I.am.concatenating.and.minimizing/>
         </sequential>
    </for>
</target>

我认为有四种可能性:

  • 使用调用进行复制的文件
  • 使用 (这可能不起作用,因为它可能无法包含在目标中)
  • 使用(这可能不起作用,因为它可能无法包含在目标中)
  • 使用实体包含.
  • Use <ant/> to call the files that do the copying
  • Use <import/> (which might not work because it might not be able to be included inside a target)
  • Use <include/> (which might not work because it might not be able to be included inside a target)
  • Use the Entity Include.

我从不热衷于使用 尽管现在可能是这样做的好时机.Entity Include 的想法会奏效,但这是大多数人不理解的东西,我担心它会引起必须支持我正在做的事情的人的困惑. 在这种情况下可能无法使用,但我仍然很好奇它们的区别是什么.

I am never crazy about using <ant/> or <antcall> although this might be a good time to do this. The Entity Include idea will work, but that's something most people don't understand, and I am afraid it will cause confusion for people who have to support what I'm doing. The <import> and <include> may not be able to be used in this situation, but I'm still curious what the differences are.

推荐答案

导入文档解释差异:

简短版本:如果您打算覆盖目标,请使用导入,否则使用包含.

The short version: Use import if you intend to override a target, otherwise use include.

使用导入时,导入的目标最多可使用两个名称.他们的正常"name 不带任何前缀,并且可能带有前缀名称(as 属性的值或导入项目的 name 属性,如果有).

When using import the imported targets are available by up to two names. Their "normal" name without any prefix and potentially with a prefixed name (the value of the as attribute or the imported project's name attribute, if any).

当使用 include 时,包含的目标仅在前缀形式中可用.

When using include the included targets are only available in the prefixed form.

使用导入时,导入目标的依赖属性保持不变,即使用正常";名称并允许您覆盖依赖项列表中的目标.

When using import, the imported target's depends attribute remains unchanged, i.e. it uses "normal" names and allows you to override targets in the dependency list.

当使用 include 时,包含的目标不能被覆盖,并且它们的依赖属性被重写,以便使用前缀名称.这允许包含文件的编写者控制调用哪个目标作为依赖项的一部分.

When using include, the included targets cannot be overridden and their depends attributes are rewritten so that prefixed names are used. This allows writers of the included file to control which target is invoked as part of the dependencies.

使用不同的前缀可以多次包含同一个文件,不能多次导入同一个文件.

It is possible to include the same file more than once by using different prefixes, it is not possible to import the same file more than once.

这篇关于Ant&lt;import&gt;与&lt;包括&gt;任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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