如何将参数传递给 Ant 任务? [英] How do I pass an argument to an Ant task?
问题描述
我对 Ant 不太熟悉,但我们将它用作构建工具.现在,我们可以运行蚂蚁测试",它将运行所有单元测试.
I'm not very good with Ant, but we're using it as a build tool. Right now, we can run "ant test" and it'll run through all the unit tests.
但是,我希望能够执行类似 ant test some_module
的操作,并让它接受 some_module
作为参数,并且只测试它.
However, I'd love to be able to do something like ant test some_module
and have it accept some_module
as a parameter, and only test that.
我找不到如何将命令行参数传递给 Ant - 有什么想法吗?
I haven't been able to find how to pass command line args to Ant - any ideas?
推荐答案
一种解决方案可能如下.(我有一个项目可以做到这一点.)
One solution might be as follows. (I have a project that does this.)
有一个类似于 test
的单独目标,带有 fileset
,将测试限制为一个类.然后在 ant 命令行中使用 -D
传递该类的名称:
Have a separate target similar to test
with a fileset
that restricts the test to one class only. Then pass the name of that class using -D
at the ant command line:
ant -Dtest.module=MyClassUnderTest single_test
在 build.xml 中(高度缩减):
In the build.xml (highly reduced):
<target name="single_test" depends="compile" description="Run one unit test">
<junit>
<batchtest>
<fileset dir="${test.dir}" includes="**/${test.module}.class" />
</batchtest>
</junit>
</target>
这篇关于如何将参数传递给 Ant 任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!