ant dependent 与 antcall
定义顺序构建步骤时,我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最大的区别是 Ant 将确保通过
depends
声明的依赖项最多被调用一次。 例如:如果我调用 target
d
,<调用 code>b 和c
。但是,a
仅调用一次(即使b
和c
都依赖于它)。现在假设我们决定使用
antcall
而不是目标d
的依赖:调用目标
d
现在将调用目标b
和c
;但是,目标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:If I call target
d
,b
andc
are called. However,a
is only called once (even though bothb
andc
depends on it).Now suppose we decide to use
antcall
instead of depends for targetd
:Calling target
d
will now call targetsb
andc
; however, targeta
will get called twice, once forb
and then again forc
.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 whatdepends
is for. So when would you use it? Theantcall
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 thegoto
of Ant--it's evil. Most well-written build scripts simply don't need it except in unusual cases.两种方法之间的主要区别在于,
depends
中的目标总是执行,而antcall
中的目标仅在包含目标执行时才执行。一个澄清的例子:
这里,
b
将始终被执行,而a
只有在定义了some.flag
时才会执行。这里,只有当
a
存在时,即定义了some.flag
时,b
才会被执行。The main difference between both approaches is that targets in
depends
are always executed, while targets inantcall
are executed only if the containing target is.A clarifying example:
Here,
b
will always be executed, whilea
will be executed only ifsome.flag
is defined.Here,
b
will only be executed ifa
is, i.e. ifsome.flag
is defined.Antcall 相对较少使用,因为:
换句话说,antcall 是一个全新的独立 Ant 进程在运行。
Antcall is relatively rarely used, because:
In other words, antcall is whole new isolated Ant process running.
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.
这意味着在执行目标 a 中的任何语句或任何标记之前,ANT 会确保目标 b 成功执行,
并且在从调用目标执行某些语句或标记后,您可以使用 antcall 调用任何目标。
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.