Call ant several times with different parameters

Is it possible in Ant to repeatedly call the same target with different parameters?

My command is as follows:

ant unittest -Dproject='proj1' unittest -Dproject='proj2' 

The problem is that unittest runs twice, but only for proj2:

 unittest: [echo] Executing unit test for project proj2 unittest: [echo] Executing unit test for project proj2 

I know that I can run two separate Ant commands, but this will cause additional problems with the unit test report files.

+7
ant
source share
1 answer

You can add another target to run your unittest target twice with different parameters using the antcall task, for example.

 <project name="test" default="test"> <target name="test"> <antcall target="unittest"> <param name="project" value="proj1"/> </antcall> <antcall target="unittest"> <param name="project" value="proj2"/> </antcall> </target> <target name="unittest"> <echo message="project=${project}"/> </target> </project> 

Output:

 test: unittest: [echo] project=proj1 unittest: [echo] project=proj2 BUILD SUCCESSFUL Total time: 0 seconds 

Alternatively, you can change the unittest target as a macrodef :

 <project name="test" default="test"> <target name="test"> <unittest project="proj1"/> <unittest project="proj2"/> </target> <macrodef name="unittest"> <attribute name="project"/> <sequential> <echo message=" project=@ {project}"/> </sequential> </macrodef> </project> 
+19
source share

All Articles