Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6058985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:39:37+00:00 2026-05-23T08:39:37+00:00

I have the following ant script that I can’t seem to find a way

  • 0

I have the following ant script that I can’t seem to find a way to make fail when parallel is set to true for antcontrib’s foreach task. Any ideas?

<project name="asdf" >
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="../lib/ant/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>
    <target name="build">
        <foreach target="exex-subant" param="foreach.dir" parallel="true" maxthreads="4" inheritall="true" list="1,2,3">
            <param name="target" value="build" />
        </foreach>
    </target>

    <target name="exex-subant">
        <fail>test</fail>
    </target>
</project>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:39:38+00:00Added an answer on May 23, 2026 at 8:39 am

    This occurs because when executed in parallel, <foreach> uses the <parallel> task, but does not set the “failonany” property, or give any way to say that the task should fail if any iteration failed.

    Fortunately, there is a relatively easy workaround, which is to use <for> instead of <foreach>. In your example, that would look like this:

    <target name="build">
        <for param="foreach.dir" parallel="true" list="1,2,3">
            <sequential>
                <antcall target="exex-subant" inheritall="true">
                    <param name="target" value="build" />
                    <param name="foreach.dir" value="@{foreach.dir}" />
                </antcall>
            </sequential>
        </for>
    </target>
    

    Note that you have to explicitly pass in the foreach.dir property, which will then be accessible in the exex-subant target as ${foreach.dir}.

    This will execute all iterations in parallel, but the script will fail if any one of them fails (it will not execute anything beyond the for task).

    Note that in order to use the for task, you’ll need ant 1.6 or higher, and will need to change your taskdef to:

    <taskdef resource="net/sf/antcontrib/antlib.xml">
        <classpath>
            <pathelement location="../lib/ant/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>
    

    If for some reason you need to support older versions of ant, then you would have to change the exex-subant target slightly, so that it changed something when it failed. For example, you could wrap the current logic in exex-subant within a try/catch, and in the catch block it could create a file. Then after the foreach terminates you can check to see if that file exists, and fail the build if it does. That way, if any execution of the foreach fails, the ant script will fail after the foreach finishes.

    Note that you can’t just set a property in exex-subant on failure, since the property won’t propagate back to the foreach loop (which is why I suggested creating a file). But I’d strongly recommend just using the for task and requiring ant 1.6 or higher.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ant script that does a headless build using the following ant
I have an ant build script that errors out with the following message. javac
I have an ant script with the following header: <project name=Simple ActiveJDBC Example default=clean
We currently have an ant task that contains something similar to the following: <filelist
I am using apache ant in the following way: I have projects P1, P2,
I have following target in mz ant script to build my java application <target
I have a script that repeatedly runs an Ant buildfile and scrapes output into
The ANT build script I have does the following: Perform the builds on Windows
I have an Ant project that uses a bit of Coffee Script. I would
I have following ant script to generate the jar file <project name=myProject basedir=. default=jar>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.