Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>See the difference, between <strong>include</strong> and <strong>import</strong> in the Ant manual. Also use <strong>macrodefs</strong>.</p> <p>I've slightly adapted your example, you'll need several files: build.xml, common.xml and macrodef_project_setup.xml</p> <p><strong>build.xml</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;project name="Ant_Test" basedir="." default="init"&gt; &lt;import file="common.xml"/&gt; &lt;!-- This target overridden by the one in common.xml --&gt; &lt;target name="common.init"/&gt; &lt;target name="setup" depends="init"/&gt; &lt;target name="do.several" depends="common.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="common.setup"&gt; &lt;echo message="In do.first" /&gt; &lt;/target&gt; &lt;target name="do.second" depends="common.setup"&gt; &lt;echo message="In do.second" /&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p><strong>common.xml</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;project name="common"&gt; &lt;target name="init"&gt; &lt;project_setup option="Stack.Over.Flow"/&gt; &lt;/target&gt; &lt;target name="setup"&gt; &lt;/target&gt; &lt;import file="macrodef_project_setup.xml"/&gt; &lt;/project&gt; </code></pre> <p><strong>macrodef</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;project name="project_setup" basedir="."&gt; &lt;macrodef name="project_setup"&gt; &lt;attribute name="option" default=""/&gt; &lt;sequential&gt; &lt;!-- some process --&gt; &lt;echo&gt;THIS IS MY SETUP OPTION: @{option}&lt;/echo&gt; &lt;/sequential&gt; &lt;/macrodef&gt; &lt;/project&gt; </code></pre> <p><strong>Output:</strong></p> <pre><code>ant -p Buildfile: build.xml Main targets: Other targets: common.setup do.first do.second do.several init setup Default target: init </code></pre> <p><em>Default target is now init.</em></p> <pre><code>ant Buildfile: build.xml Ant_Test.init: [echo] In setup initialization [echo] THIS IS MY SETUP OPTION: Stack.Over.Flow </code></pre> <p><em>But you could still use ant setup.</em></p> <pre><code>ant setup Buildfile: build.xml Ant_Test.init: [echo] In setup initialization [echo] THIS IS MY SETUP OPTION: Stack.Over.Flow </code></pre> <p><em>Run it with do.several.</em></p> <pre><code>ant do.several Buildfile: build.xml Ant_Test.init: [echo] In setup initialization [echo] THIS IS MY SETUP OPTION: Stack.Over.Flow Ant_Test.do.several: [echo] In do.several, calling do.first Ant_Test.do.first: [echo] In do.first [echo] In do.several, calling do.second Ant_Test.do.second: [echo] In do.second </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload