Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute an Ant task only when source files have been modified?

There must be an easy way to do this. I build a Flex app using ant that depends on a SWC library, which works fine except that it rebuilds the library whether it needs to or not. How do I tell ant to only run the task if any of the sources files of the library (*.as, *.mxml) are newer than the SWC?

I've looked at <dependset> but it only seems to delete files, not determine whether a task should be run or not. <depend> seems to expect a one-to-one relationship between the source and target files rather than a one-to-many relationship -- I have many input files and one output file, but no intermediate object files.

Thanks a lot, Alex

like image 629
user15899 Avatar asked Feb 02 '09 16:02

user15899


People also ask

How do you run an ant task?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

Which one code is used to set the destination directory in Ant?

Destination path is specified using the destdir folder (e.g build. dir). You could filter the javadoc task by specifying the package names which are to be included. This is achieved by using the packagenames attribute, a comma separated list of package files.

What is the ant command?

Ant allows command line arguments, even arguments which contains space characters. It supports <arg> element to pass arguments and uses various attribute given below.

What is Java Ant task?

This task is used to execute Java code inside the Ant JVM. We can also use other (outside) JVM by setting fork attribute true. To get input for the fork JVM, we can use input and inputstring attributes.


1 Answers

You may use the Ant uptodate task to create a property, and execute your other target only if that property is set.

I don't know much about flex, but you probably want something like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="compile">

   <target name="checkforchanges">
      <uptodate property="nochanges">
         <srcfiles dir="." includes="**/*.as"/>
         <srcfiles dir="." includes="**/*.mxml"/>
         <mapper to="applicaton.flex"/>
      </uptodate>
   </target>

   <target name="compile" depends="checkforchanges" unless="nochanges">
      ...
   </target>

</project>
like image 126
Mnementh Avatar answered Oct 14 '22 16:10

Mnementh