title: Avoiding re-building prerequisites in Ant
body: <p>I have an existing Ant project and would like to speed up the build process
  by avoiding re-building components that are already up to date.</p>
  
  <p>Ant permits you to specify that one target depends on another, but by
  default every prerequisite is always rebuilt, even if it is already up to
  date.  (This is a key difference between Ant and make.  By default, make
  only re-builds a target when needed -- that is, if some prerequisite is
  newer.)</p>
  
  <pre><code>&lt;uptodate property="mytarget.uptodate"&gt;  // in set.mytarget.uptodate task
    ...
  &lt;/uptodate&gt;
  &lt;!-- The prerequisites are executed before the "unless" is checked. --&gt;
  &lt;target name="mytarget" depends="set.mytarget.uptodate" unless="mytarget.uptodate"&gt;
    ...
  &lt;/target&gt;
  </code></pre>
  
  <p>To make Ant re-build prerequisites only if necessary, there seem to be two
  general approaches within Ant.</p>
  
  <p>The first approach is to use the <code>uptodate</code> task to set a property.  Then,
  your task can test the property and build only if the property is (not)
  set.</p>
  
  <pre><code>&lt;uptodate property="mytarget.uptodate"&gt;  // in set.mytarget.uptodate task
    ...
  &lt;/uptodate&gt;
  &lt;!-- The prerequisites are executed before the "unless" is checked. --&gt;
  &lt;target name="mytarget" depends="set.mytarget.uptodate" unless="mytarget.uptodate"&gt;
    ...
  &lt;/target&gt;
  </code></pre>
  
  <p>An alternate first approach is to use the <code>outofdate</code> task from ant contrib.
  It's nicer in that it is just one target without a separate property being
  defined; by contrast, outofdate requires separate targets to set and to
  test the property.</p>
  
  <p>The second approach is to create a <code>&lt;fileset&gt;</code> using the <code>&lt;modified&gt;</code>
  selector.  It calculates MD5 hashes for files and selects files whose MD5
  differs from earlier stored values.  It's optional to set</p>
  
  <pre><code> &lt;param name="cache.cachefile"     value="cache.properties"/&gt;
  </code></pre>
  
  <p>inside the  selector; it defaults to "cache.properties".  Here is
  an example that copies all files from src to dest whose content has
  changed:</p>
  
  <pre><code>    &lt;copy todir="dest"&gt;
          &lt;fileset dir="src"&gt;
              &lt;modified/&gt;
          &lt;/fileset&gt;
      &lt;/copy&gt;
  </code></pre>
  
  <p>Neither of these is very satisfactory, since it requires me to write Ant
  code for a process (avoiding re-building) that ought to be automatic.</p>
  
  <p>There is also Ivy, but I can't tell from its documentation whether it
  provides this feature.  The key use case in the Ivy documentation seems to
  be downloading subprojects from the Internet rather than avoiding wasted
  work by staging the parts of a single project.  Maven provides similar
  functionality, with the same use case highlighted in its documentation.
  (Moving an existing non-trivila project to Maven is said to be a nightmare;
  by contrast, starting greenfield development with Maven is more palatable.)</p>
  
  <p>Is there a better way?</p>