You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dean Del Ponte <de...@cornerstone.net> on 2008/10/02 16:25:05 UTC

How to stop ant execution if one target fails

I'm using ant to build my project.  When running ant from the command line, I'm passing in multiple targets.  For example:

     ant -verbose clean build jar findbugs pmd

Ant will execute the targets clean, build, jar, findbugs, and pmd in that order.

My problem is that if one of the targets fail, ant continues with the next target.  I would like it to stop execution if one fails.

For example, if the "jar" target fails, ant should not call the findbugs and pmd targets.

Any help is appreciated.

Dean Del Ponte
Software Consultant, Cornerstone Consulting, Inc.
www.cornerstone.net
Our Experts. Your Edge


AW: How to stop ant execution if one target fails

Posted by Ja...@rzf.fin-nrw.de.
A build fails, if a BuildException occurs during task execution.
This is the case on some tasks when they "find" some mistakes like <javac> and invalid java source.
An other example is <junit> with failing tests, but here you can specify whether the build should fail or failing test should just be reporting using <junit haltonfailure|haltonerror>.
With <fail> you can directly throw a BE and the build will halt.

I am not sure, but I think you can "overwrite" this behaviour using -k(eep-going).
	ant -h
	ant [options] [target [target2 [target3] ...]]
	Options:
	  -keep-going, -k        execute all targets that do not depend
	                         on failed target(s)
Here Ant would report the failing tasks/targets and try the next target which dont rely on a prior successful target.


It is not unusual to keep the failure-status in a property and react on that.
	<target name="test" depends="compile">
		<junit failureproperty="junit.failed"
	<target name="checkstyle">
		<cs:checkstyle failOnViolation="false" failureProperty="checkstyle.failed"
	<target name="pmd">
		<pmd:pmd failuresPropertyName="pmd.failed"
	<target name="findbugs">
		<fb:findbugs errorProperty="findbugs.failed"
	<target name="metrics" depends="-checkmetrics" unless="metrics.failed">
		<echo>All metrics passed</echo>
	</target>
	<target name="-checkmetrics" depends="test,checkstyle,pmd,findbugs">
		<condition property="metrics.failed"><or>
			<isset property="junit.failed"/>
			<isset property="pmd.failed"/>
			<isset property="findbugs.failed"/>
			<isset property="checkstyle.failed"/>
		</or></condition>
	</target>


Jan



> -----Ursprüngliche Nachricht-----
> Von: John5342 [mailto:john5342@googlemail.com] 
> Gesendet: Donnerstag, 2. Oktober 2008 21:39
> An: Ant Users List
> Betreff: Re: How to stop ant execution if one target fails
> 
> If the names of the targets are indeed what they do then most 
> of them should
> probably always be done in a particular order in which case 
> make each one
> depend on the next similar to the following.
> 
> <target name="jar" depends="build" ....>
> ....
> </target>
> 
> Then if you were to run "ant jar" then build will be automatically run
> before jar and if build fails then jar will not be run. You 
> should be able
> to do this for most of your targets and then all required targets will
> always be automatically run and you only call the target you 
> actually need.
> 
> Hope that helps you.
> 
> John.
> 
> 2008/10/2 Dean Del Ponte <de...@cornerstone.net>
> 
> > I'm using ant to build my project.  When running ant from 
> the command line,
> > I'm passing in multiple targets.  For example:
> >
> >     ant -verbose clean build jar findbugs pmd
> >
> > Ant will execute the targets clean, build, jar, findbugs, 
> and pmd in that
> > order.
> >
> > My problem is that if one of the targets fail, ant 
> continues with the next
> > target.  I would like it to stop execution if one fails.
> >
> > For example, if the "jar" target fails, ant should not call 
> the findbugs
> > and pmd targets.
> >
> > Any help is appreciated.
> >
> > Dean Del Ponte
> > Software Consultant, Cornerstone Consulting, Inc.
> > www.cornerstone.net
> > Our Experts. Your Edge
> >
> >
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: How to stop ant execution if one target fails

Posted by John5342 <jo...@googlemail.com>.
If the names of the targets are indeed what they do then most of them should
probably always be done in a particular order in which case make each one
depend on the next similar to the following.

<target name="jar" depends="build" ....>
....
</target>

Then if you were to run "ant jar" then build will be automatically run
before jar and if build fails then jar will not be run. You should be able
to do this for most of your targets and then all required targets will
always be automatically run and you only call the target you actually need.

Hope that helps you.

John.

2008/10/2 Dean Del Ponte <de...@cornerstone.net>

> I'm using ant to build my project.  When running ant from the command line,
> I'm passing in multiple targets.  For example:
>
>     ant -verbose clean build jar findbugs pmd
>
> Ant will execute the targets clean, build, jar, findbugs, and pmd in that
> order.
>
> My problem is that if one of the targets fail, ant continues with the next
> target.  I would like it to stop execution if one fails.
>
> For example, if the "jar" target fails, ant should not call the findbugs
> and pmd targets.
>
> Any help is appreciated.
>
> Dean Del Ponte
> Software Consultant, Cornerstone Consulting, Inc.
> www.cornerstone.net
> Our Experts. Your Edge
>
>

RE: How to stop ant execution if one target fails

Posted by "Lenhof,Danny" <Da...@gartner.com>.
You may want to use something like this.... <fail unless="workspace"
message="The workspace property needs to be set!"/>

-Danny
-----Original Message-----
From: Dean Del Ponte [mailto:dean.delponte@cornerstone.net] 
Sent: Thursday, October 02, 2008 10:25 AM
To: user@ant.apache.org
Subject: How to stop ant execution if one target fails

I'm using ant to build my project.  When running ant from the command
line, I'm passing in multiple targets.  For example:

     ant -verbose clean build jar findbugs pmd

Ant will execute the targets clean, build, jar, findbugs, and pmd in
that order.

My problem is that if one of the targets fail, ant continues with the
next target.  I would like it to stop execution if one fails.

For example, if the "jar" target fails, ant should not call the findbugs
and pmd targets.

Any help is appreciated.

Dean Del Ponte
Software Consultant, Cornerstone Consulting, Inc.
www.cornerstone.net
Our Experts. Your Edge


This e-mail message, including any attachments, is for the sole use of the person to whom it has been sent, and may contain information that is confidential or legally protected. If you are not the intended recipient or have received this message in error, you are not authorized to copy, distribute, or otherwise use this message or its attachments. Please notify the sender immediately by return e-mail and permanently delete this message and any attachments.  Gartner makes no warranty that this e-mail is error or virus free. 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org