ant dependent 与 antcall

发布于 2024-11-05 14:25:05 字数 341 浏览 5 评论 0原文

定义顺序构建步骤时,我使用 target 元素的 depends 属性。我最近看到一个 ant 文件,其中构建序列是由目标内的 antcall 元素定义的。 为了说明:

<target name="a" depends="b">
...</target>

vs

<target name="a">
<antcall target="b"/>
...</target>

两种方法之间是否有真正的区别?其中之一更可取吗?

When defining sequential build steps I use the depends attribute of the target element. I have recently seen an ant file, where the build sequence was defined by antcall elements inside the targets.
To illustrate :

<target name="a" depends="b">
...</target>

vs

<target name="a">
<antcall target="b"/>
...</target>

Is there a real difference between the two approaches? Is one of them preferable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

回首观望 2024-11-12 14:25:05

最大的区别是 Ant 将确保通过 depends 声明的依赖项最多被调用一次。 例如:

<target name="a" />

<target name="b" depends="a" />

<target name="c" depends="a" />

<target name="d" depends="b, c" />

如果我调用 target d,<调用 code>b 和 c。但是,a 仅调用一次(即使 bc 都依赖于它)。

现在假设我们决定使用 antcall 而不是目标 d 的依赖:

<target name="d">
   <antcall target="b" />
   <antcall target="c" />
</target>

调用目标 d 现在将调用目标 bc;但是,目标a将被调用两次,一次为b调用,然后再次为c调用。

换句话说,antcall 回避了作为 Ant 基石的正常依赖规则。

我认为 antcall 不应该用来替代普通的类似 Ant 的依赖项;这就是 depends 的用途。那么你什么时候会使用它呢? antcall 任务确实允许您控制定义哪些属性和引用(这就是创建新 Ant 环境的原因 - 以及它如此慢的原因),因此它可以用于创建相同的变体事物;例如,可能有两个罐子,一个带有调试符号,一个没有调试符号。

然而,过度使用 antcall 会导致构建脚本缓慢、脆弱且难以维护。将其视为 Ant 的 goto ——这是邪恶的。大多数编写良好的构建脚本根本不需要它,除非在特殊情况下。

The biggest difference is that Ant will ensure that dependencies declared via depends are called at most once. For example:

<target name="a" />

<target name="b" depends="a" />

<target name="c" depends="a" />

<target name="d" depends="b, c" />

If I call target d, b and c are called. However, a is only called once (even though both b and c depends on it).

Now suppose we decide to use antcall instead of depends for target d:

<target name="d">
   <antcall target="b" />
   <antcall target="c" />
</target>

Calling target d will now call targets b and c; however, target a will get called twice, once for b and then again for c.

In other words, antcall sidesteps the normal dependency rules that are the cornerstone of Ant.

I don't think antcall should be used as a substitute for normal Ant-like dependencies; that's what depends is for. So when would you use it? The antcall task does allow you to control what properties and references are defined (which is why a new Ant environment is created--and why it's so slow) so it can be used to create variants of the same thing; e.g., maybe two jars, one with and one without debug symbols.

Overusing antcall, however, creates slow, brittle, and hard to maintain build scripts. Think of it as the goto of Ant--it's evil. Most well-written build scripts simply don't need it except in unusual cases.

世俗缘 2024-11-12 14:25:05

两种方法之间的主要区别在于,depends 中的目标总是执行,而 antcall 中的目标仅在包含目标执行时才执行。

一个澄清的例子:

<target name="a" depends="b" if="some.flag">

</target>

这里,b将始终被执行,而a只有在定义了some.flag时才会执行。

<target name="a" if="some.flag">
    <antcall target="b" />
</target>

这里,只有当 a 存在时,即定义了 some.flag 时,b 才会被执行。

The main difference between both approaches is that targets in depends are always executed, while targets in antcall are executed only if the containing target is.

A clarifying example:

<target name="a" depends="b" if="some.flag">

</target>

Here, b will always be executed, while a will be executed only if some.flag is defined.

<target name="a" if="some.flag">
    <antcall target="b" />
</target>

Here, b will only be executed if a is, i.e. if some.flag is defined.

何以笙箫默 2024-11-12 14:25:05

Antcall 相对较少使用,因为:

被调用的目标在新的
项目;请注意,这意味着
属性、引用等设置
被调用的目标不会持续回来
到调用项目。

换句话说,antcall 是一个全新的独立 Ant 进程在运行。

Antcall is relatively rarely used, because:

The called target(s) are run in a new
project; be aware that this means
properties, references, etc. set by
called targets will not persist back
to the calling project.

In other words, antcall is whole new isolated Ant process running.

无语# 2024-11-12 14:25:05

antcall 是 ant 的 GOTO。太可怕了。这是用无法维护的垃圾建造老鼠窝的好方法。除了 ant-contrib 之外,它是发现过于复杂且难以维护的 ant 文件的最佳方式。 (即使是一个好的 antfile 也很粗糙)

如果你的依赖设置正确,你应该能够成功运行任何目标,这与 antcall 模式不同。

没有人触及的另一个原因是 vizant,如果它是一个复杂的构建,那么生成目标依赖关系图的能力非常好。如果你使用 antcall 你就完蛋了。

我希望 @Vladimir Dyuzhev 是正确的,antcall 很少被使用 - 我去过很多商店,那里这是常态。

antcall is the GOTO of ant. It is terrible. It's a great way to make a rats nest of unmaintainable cruft. Next to ant-contrib it's the best way to smell an overly complicated hard to maintain ant file. (even a good antfile is rough)

If your depends are set properly you should be able to run any target up to that point successfully, unlike the antcall pattern.

Another reason nobody has touched on is vizant, the ability to generate a graph of your target dependencies is pretty sweet if it's a complicated build. If you use antcall you're screwed.

I wish @Vladimir Dyuzhev was correct that antcall is rarely used - I've been to a lot of shops where it's the norm.

流星番茄 2024-11-12 14:25:05
  <target name="a" depends="b"> ...</target> 

这意味着在执行目标 a 中的任何语句或任何标记之前,ANT 会确保目标 b 成功执行,

并且在从调用目标执行某些语句或标记后,您可以使用 antcall 调用任何目标。

  <target name="a" depends="b"> ...</target> 

This means beforeing executing any statement or any tag from target a, ANT makes it sure that target b is executed successfully

And you can call any target using antcall after some statements or tags gets executed from calling target.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文