This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
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: 518
    
    2

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: 518
    
    2

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

Joined: May 14, 2008
Posts: 5812
    
    7

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: 518
    
    2

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: 3274
    
    5

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://aspose.com/file-tools
 
subject: How to do conditional execution ofa target
 
Similar Threads
Ant and log4j problem
Executing multiple targets in subprojects
&lt;junit&gt; problem with Ant
"include" capability?
ANT file