title: Is there a way to guarantee that an ant dependency is run only once?
body: <p>My question is similar to <a href="https://stackoverflow.com/questions/1861569/avoiding-re-building-prerequisites-in-ant">avoiding-re-building-prerequisites-in-ant</a>, except that my need doesn't involve created objects, but processes invoked, so the solutions discussed there won't work for me. At least I think so - but I'm new to ant.</p>
  
  <p>My situation is that I'm writing a set of ant targets, and I need the lets-call-it <em>setup</em> target to be executed once and only once, no matter which target is invoked.  Here's a greatly simplified example:</p>
  
  <pre><code>
      &lt;?xml version="1.0"?&gt;
      &lt;project name="Ant_Test" basedir="."&gt;
        &lt;target name="setup"&gt;
          &lt;echo message="In setup" /&gt;
        &lt;/target&gt;
        &lt;target name="do.several" depends="setup"&gt;
          &lt;echo message="In do.several, calling do.first" /&gt;
          &lt;antcall target="do.first" /&gt;
          &lt;echo message="In do.several, calling do.second" /&gt;
          &lt;antcall target="do.second" /&gt;
        &lt;/target&gt;
        &lt;target name="do.first" depends="setup"&gt;
          &lt;echo message="In do.first" /&gt;
        &lt;/target&gt;
        &lt;target name="do.second" depends="setup"&gt;
          &lt;echo message="In do.second" /&gt;
        &lt;/target&gt;
      &lt;/project&gt;
  </code></pre> 
  
  <p>I need <em>setup</em> to be invoked exactly once, regardless of whether <em>do.several</em>, <em>do.first</em>, or <em>do.second</em> are invoked.  With my naive attempt above, invoking do.several results in three calls to <em>setup</em>.  </p>
  
  <p>I've thought of setting a property (let's call it <em>setup.has.been.invoked</em>), and using that to conditionally invoke <em>setup</em> from within each target, but it appears that property setting is limited to the scope it's done in, so if in <em>setup</em>, I set <em>setup.has.been.invoked</em> to true, that value only exists within <em>setup</em>.</p>
  
  <p>What am I missing?  Is there a section of the tutorials or online documentation I've skipped?  Any pointers or hints?</p>