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

  • Home
  • SEARCH
  • 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 7444427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:30:42+00:00 2026-05-29T11:30:42+00:00

I have an ant task that executes some command on a list of files.

  • 0

I have an ant task that executes some command on a list of files.
I would like, on consecutive builds, to avoid from re-running the command on files that have passed the command with success and haven’t changed.

For example: (here the command is xmllint)

 <target name="xmllint-files">
    <apply executable="xmllint">
        <srcfile/>
        <fileset dir="." includes="*.xml">
            <modified/>
        </fileset>

    </apply>
</target>

The problem is that even the files where xmlint fails are considered as modified and therefore xmllint will not be re-run on them on consecutive builds. Obviously, this is not the desired behavior.

Two remarks:

  1. I am looking for a general solution and not only a solution for xmllint.
  2. I want to solve the problem totally inside ant without creating
    external scripts.
  • 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-29T11:30:44+00:00Added an answer on May 29, 2026 at 11:30 am

    This code uses the Groovy ANT task to do the following:

    • Implement a custom groovy selector, selecting the XML files to be processed based on a MD5 checksum check.
    • Invoke xmllint on each file and store it’s checksum upon successful completion (This prevents re-execution of xmllint unless the file’s contents are changed.

    Example:

    <project name="demo" default="xmllint">
    
        <!--
        ======================
        Groovy task dependency
        ======================
        -->
        <path id="build.path">
            <pathelement location="jars/groovy-all-1.8.6.jar"/>
        </path>
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
    
        <!--
        ==============================================
        Select files to be processed 
        MD5 checksums located in "checksums" directory
        ==============================================
        -->
        <target name="select-files">
            <fileset id="unprocessedfiles" dir=".">
                <include name="*.xml"/>
                <exclude name="build.xml"/>
                <scriptselector language="groovy" classpathref="build.path">
                    def ant = new AntBuilder()
                    ant.checksum(file:filename, toDir:"checksums", verifyProperty:"isMD5ok")
    
                    self.selected = (ant.project.properties.isMD5ok == "false") ? true : false
                </scriptselector>
            </fileset>
        </target>
    
        <!--
        =============================================================
        Process each file 
        Checksum is saved upon command success, prevents reprocessing
        =============================================================
        -->
        <target name="xmllint" depends="select-files">
            <groovy>
                project.references.unprocessedfiles.each { file ->
                    ant.exec(executable:"xmllint", resultproperty:"cmdExit") {
                        arg(value:file)
                    }
                    if (properties.cmdExit == "0") {
                        ant.checksum(file:file.toString(), toDir:"checksums")
                    }
                }
            </groovy>
        </target>
    
    </project>
    

    Note:

    • This complex requirement cannot be implemented using the original apply ANT task. One call to xmllint command might succeed whereas another might fail.
    • A subdirectory called “checksums” is created to store the MD5 checksum files.
    • The groovy jar can be downloaded from Maven Central

    Original answer

    Use the ANT modified selector

    <project name="demo" default="xmllint">
    
        <target name="xmllint">
            <apply executable="xmllint">
                <srcfile/>
                <fileset dir="." includes="*.xml">
                    <modified/>
                </fileset>
            </apply>
        </target>
    
    </project>
    

    A property file called “cache.properties” will be created in the build directory. It records file digests, used determine if the file has been changed since the last build run.

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

Sidebar

Related Questions

I have an ant build script that needs to pull files down from a
I have this simple Ant task that lists all '.png' files in a folder:
I would like to write a simple Ant task that would interact with an
I'm trying to create an ANT task that takes some database properties and executes
We currently have an ant task that contains something similar to the following: <filelist
I have an Ant script that performs a copy operation using the 'copy' task
I have a ruby application that executes ant as a subprocess using backtick. This
I have here a Windows distribution server that runs an ANT task to build
I have an Ant project that uses a bit of Coffee Script. I would
I have an Ant task to call a java process that takes a file

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.