有没有办法概括 Apache ANT 目标?
我们有一个 Apache ANT 脚本来构建我们的应用程序,然后将生成的 JAR 文件签入版本控制(在本例中为 VSS)。 然而,现在我们进行了一项更改,要求我们为此项目构建 2 个 JAR 文件,然后将这两个文件签入 VSS。
将原始 JAR 文件签入 VSS 的当前目标通过某些属性发现 JAR 文件的名称。 有没有一种简单的方法来“概括”这个目标,以便我可以重用它来签入具有任何名称的 JAR 文件? 在普通语言中,这显然需要一个函数参数,但据我所知,ANT 中确实没有等效的概念。
We have an Apache ANT script to build our application, then check in the resulting JAR file into version control (VSS in this case). However, now we have a change that requires us to build 2 JAR files for this project, then check both into VSS.
The current target that checks the original JAR file into VSS discovers the name of the JAR file through some property. Is there an easy way to "generalize" this target so that I can reuse it to check in a JAR file with any name? In a normal language this would obviously call for a function parameter but, to my knowledge, there really isn't an equivalent concept in ANT.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通常认为对二进制文件进行版本控制是一个坏主意,我不建议这样做。 但如果你绝对需要,你可以使用 antcall 结合 param 来传递参数并调用目标。
您可以在此处找到有关 antcall 任务的更多信息。
It is generally considered a bad idea to version control your binaries and I do not recommend doing so. But if you absolutely have to, you can use antcall combined with param to pass parameters and call a target.
You can find more information about the antcall task here.
看一下 Ant 宏。 它们允许您为 Ant 构建定义可重用的“例程”。 您可以在此处找到示例(第 15 项)。
Take a look at Ant macros. They allow you to define reusable "routines" for Ant builds. You can find an example here (item 15).
另请查看 subant 任务,它允许您在多个构建文件上调用同一目标:
Also check out the subant task, which lets you call the same target on multiple build files:
您可以使用 Gant 通过 groovy 做你想做的事情或者看看 常规蚂蚁任务。
You can use Gant to script your build with groovy to do what you want or have a look at the groovy ant task.
我建议使用 宏 而不是 subant/antcall 因为主要优点是宏的一个优点是您可以完全控制传递给宏的属性(特别是如果您想添加新属性)。
您只需从目标开始重构 Ant 脚本:
创建宏(注意复制/粘贴并用 @{file} 替换):
并使用文件调用宏:
重构,“Ant 方式”
I would suggest to work with macros over subant/antcall because the main advantage I found with macros is that you're in complete control over the properties that are passed to the macro (especially if you want to add new properties).
You simply refactor your Ant script starting with your target:
creating a macro (notice the copy/paste and replacement with the @{file}):
and invoke the macros with your files:
Refactoring, "the Ant way"