File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Mail task on Target failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Mail task on Target failure" Watch "Mail task on Target failure" New topic

Mail task on Target failure

vinodh kumar
Ranch Hand

Joined: Jan 07, 2008
Posts: 41

I have an ant project where there is a set of targets. After successful completion of all targets I call mail target at the end to send a mail with attached logs with message build successful.

Now, my challenge is if one of the target fails then build exits so it will not proceed to mail target which is the last one to perform on completion of all. How can I use mail target to send mail on any target failure?

Any hints?

-Vinodh Kumar
Peter Johnson

Joined: May 14, 2008
Posts: 5852

Based on the command line options ( your two best bets are:

1) Try the -k option

2) Write a CustomExitCode class and invoke the mail target from within it.

Of course, you could always create a script that does:

ant xxx yyy
ant mail

That way the mail target would always run. You'd probably have to tweak the mail target since it would be mailing the result from the prior ant run.

Another thought: having a "finally" target that runs before exit whether the build passed or failed is a good idea. If you created a patch to do that you could submit it back to the community.

JBoss In Action
I agree. Here's the link:
subject: Mail task on Target failure
It's not a secret anymore!