命名ant目标的最佳实践是什么?
例如,您希望目标“test”运行什么?所有单元测试?所有功能测试?还是两者兼有?
运行不同类型测试(单元/功能/全部)的标准名称是什么?在J2SE中部署软件的目标名称是否有标准?在J2EE中呢?
我的项目使用ant进行Java项目、JUnit、Swing应用程序和J2EE应用程序的构建。
命名ant目标的最佳实践是什么?
例如,您希望目标“test”运行什么?所有单元测试?所有功能测试?还是两者兼有?
运行不同类型测试(单元/功能/全部)的标准名称是什么?在J2SE中部署软件的目标名称是否有标准?在J2EE中呢?
我的项目使用ant进行Java项目、JUnit、Swing应用程序和J2EE应用程序的构建。
以下目标在许多构建中都很常见。始终避免更改已知目标名称的行为。您不需要在单个项目中实现所有这些目标。
all Build and test everything; create a distribution, optionally install.
clean Delete all generated files and directories.
deploy Deploy the code, usually to a remote server.
dist Produce the distributables.
distclean Clean up the distribution files only.
docs Generate all documentation.
init Initialize the build: create directories, call <tstamp> and other common actions.
install Perform a local installation.
javadocs Generate the Javadoc pages.
printerdocs Generate printable documents.
test Run the unit tests.
uninstall Remove a local installation.
这个页面还提供了其他好的指南。
ant dist
ant test report
替代
ant compile create.distribution
ant test.data test.nondata report.junit.generate report .....
我认为这完全是个人喜好的问题,但我会使用以下命名:
test
- 用于单元测试test-integration
- 用于集成测试dbtest
- 用于数据库测试(如果它们包含在上述项目中)test-all
- 运行以上所有测试此外,我对使用test
或复数形式tests
持中立态度,我可能在不同的项目中都使用过。
你的ant targets命名约定应该非常类似于Java方法的命名约定:即简单并描述目标所执行的操作。
以下是Sun method 命名标准的摘要:
Naming a Method
Although a method name can be any legal identifier, code conventions restrict method names. By convention, method names should be a verb in lowercase or a multi-word name that begins with a verb in lowercase, followed by adjectives, nouns, etc. In multi-word names, the first letter of each of the second and following words should be capitalized. Here are some examples:
run runFast getBackground getFinalData compareTo setX isEmpty
可能最大的区别在于Ant目标的风格,应该全部使用小写字母,并用破折号分隔单词。
例如,以下目标对我来说似乎是合适的:
run-all-tests
build
clean
test-and-release
deploy
run-code-coverage-metrics
最后,请尽量使用与命名方法相同的良好判断力。如果您的目标清晰、描述明确且易于理解,则处于良好状态。
有关此主题的更详细信息,请查看Ant wiki上的Ant Style元素。