Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass an argument to an Ant task?

Tags:

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.

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.

I haven't been able to find how to pass command line args to Ant - any ideas?

like image 734
Jonathan Haddad Avatar asked Dec 16 '09 00:12

Jonathan Haddad


People also ask

How do I call Ant target from command line?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

Which argument is used to show less information to the console?

Property is a name of property and value is a value associated to the property. Ex. It is used to show less information to the console.


1 Answers

One solution might be as follows. (I have a project that does this.)

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 

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> 
like image 51
martin clayton Avatar answered Nov 13 '22 17:11

martin clayton