简体   繁体   English

蚂蚁最佳实践的一个很好的例子

[英]a Good Example of ant best practices

I have read lots of articles on Ant that explain all sorts of options, and I've read much of the documentation for Ant, but I don't really know the "right" way to do many things. 我已经阅读了很多关于Ant的文章来解释各种选项,并且我已经阅读了很多关于Ant的文档,但我并不知道做“做对”的方法很“正确”。 Can anyone recommend a Good Example illustrating how to use Ant? 任何人都可以推荐一个说明如何使用Ant的好例子吗? Something that is not too complicated but also not too simple. 一些不太复杂但也不太简单的东西。

I found this one by Doug Sparling (specifically related to Hibernate) and it looks pretty good but was wondering if you folks could comment on it, because I don't want to adopt the style of someone who has questionable habits, but it seems good to me. 我找到了Doug Sparling的这篇文章 (特别是与Hibernate有关)并且它看起来很不错但是想知道你们是否可以评论它,因为我不想采用那些有疑问习惯的人的风格,但它看起来不错对我来说。

您可能还想查看Ant Wiki中的Ant使用指南

I suggest you look at the ant scripts of open source implementations that use ant for their build script. 我建议你看一下使用ant作为构建脚本的开源实现的ant脚本。 Typically the ant scripts don't get tremendous love, but they are more robust than a typical in-house job because they are distributed to so many developers that are expected to just run them in a variety of environments. 通常情况下,ant脚本并没有得到巨大的喜爱,但它们比典型的内部工作更强大,因为它们分发给了许多开发人员,而这些开发人员只能在各种环境中运行它们。

I would argue that it is a best practice to not worry about your build script beyond the point where it gets the job done and is reasonably maintainable. 我认为最好的做法是不要担心构建脚本超出完成工作的程度并且可以合理维护。 It is, after all, not the goal of most projects to produce a good build script. 毕竟,大多数项目的目标都不是生成一个好的构建脚本。 Of course, as with any best practice, there are exceptions. 当然,与任何最佳实践一样,也有例外。

Off hand, the one I looked at for JSR-310 was decent. 手边,我为JSR-310看的那个是不错的。

I always tend to divide my targets into 2 types: 我总是倾向于将目标划分为两种类型:

1) targets that do stuff - compile, jar, etc. These have no dependencies and each do one and only one thing. 1)做东西的目标 - 编译,jar等。它们没有依赖关系,每个只做一件事。

2) targets that you might want to run - build, deploy, etc. These are where the dependencies are specified. 2)您可能想要运行的目标 - 构建,部署等。这些是指定依赖项的位置。

The reason I do this is that allows you to have runnable targets that use an arbitrary set of the doing stuff targets. 我这样做的原因是允许你拥有使用任意一组执行目标的可运行目标。 For example in a web-app it's useful to be able to deploy without compiling, running tests etc every time, which this structuring of Ant scripts allows. 例如,在Web应用程序中,每次都可以在不编译,运行测试等的情况下进行部署,这是Ant脚本的这种结构所允许的。

When I'm working with multiple modules I'll also create a master build script that contains all the common targets, which are driven by variables in module specific properties files.. 当我使用多个模块时,我还将创建一个包含所有常见目标的主构建脚本,这些目标由模块特定属性文件中的变量驱动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM