jQuery in Action, 2nd edition
The moose likes Ant, Maven and Other Build Tools and the fly likes How to do conditional execution ofa target Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Reply Bookmark "How to do conditional execution ofa target" Watch "How to do conditional execution ofa target" New topic
Author

How to do conditional execution ofa target

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 457

Hello All,

I have an ant build file from which I would call another task defined in another build file. While calling another ant, I'm supplying a property say "execute" set to true. I need to have the task executed only when execute == "true".



createTar.xml


I need to have packageZip target to be executed only when property "execute" is true. I tried options like "if", "unless" but not successful so far. Because I do not want to have impact on other build files that are calling createTar. I see recommendations on using condition, but not sure how to do that.


Regards
KumarRaja

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 457

I got this resolved using <condition><istrue> elements.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5541

Kumar, posting the ant script for the solution will help others when they come across your post in the future.


JBoss In Action
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 457

Peter Johnson wrote:Kumar, posting the ant script for the solution will help others when they come across your post in the future.


That is true.

Below is what I did to solve my problem.

buildConfig.xml will call createTar.xml. I need to control certain steps of execution based on the parameter sent from buildConfig.xml

so in my buildConfig.xml I added a parameter called "NEEDZIP" like below



Now in my createTar.xml, I did as following



I'm not sure, if this is a good approach, but could manage it for my requirement.. If anybody having a better approach, please share it here.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3268

Thanks for sharing!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to do conditional execution ofa target
 
Similar Threads
Ant and log4j problem
"include" capability?
Executing multiple targets in subprojects
&lt;junit&gt; problem with Ant
ANT file