You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ant.html 14 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Ant Task</title>
  20. </head>
  21. <body>
  22. <h2 id="ant">Ant</h2>
  23. <h3>Description</h3>
  24. <p>Runs Apache Ant on a supplied buildfile. This can be used to build subprojects. <strong>This
  25. task must not be used outside of a <code>target</code> if it invokes the same build file it is part
  26. of.</strong></p>
  27. <p>When the <var>antfile</var> attribute is omitted, the file <samp>build.xml</samp> in the supplied
  28. directory (<var>dir</var> attribute) is used.</p>
  29. <p>If no target attribute is supplied, the default target of the new project is used.</p>
  30. <p>By default, all of the properties of the current project will be available in the new project.
  31. Alternatively, you can set the <var>inheritAll</var> attribute to <q>false</q> and only
  32. &quot;user&quot; properties (i.e., those passed on the command-line) will be passed to the new
  33. project. In either case, the set of properties passed to the new project will override the
  34. properties that are set in the new project (See also the <a href="property.html">property</a>
  35. task).</p>
  36. <p>You can also set properties in the new project from the old project by using
  37. nested <code>property</code> tags. These properties are always passed to the new project and any
  38. project created in that project regardless of the setting of <var>inheritAll</var>. This allows you
  39. to parameterize your subprojects.</p>
  40. <p>When more than one nested <code>&lt;property&gt;</code> element would set a property of the same
  41. name, the one declared last will win. This is for backwards compatibility reasons even though it is
  42. different from the way <code>&lt;property&gt;</code> tasks in build files behave.</p>
  43. <p>Properties defined on the command line cannot be overridden by
  44. nested <code>&lt;property&gt;</code> elements. <em>Since Ant 1.8.0</em>, the same is true for
  45. nested structures of <code>&lt;ant&gt;</code> tasks: if a build file <var>A</var>
  46. invokes <var>B</var> via an <code>&lt;ant&gt;</code> task setting a property with a
  47. nested <code>&lt;property&gt;</code> element and <var>B</var> contains an <code>&lt;ant&gt;</code>
  48. tasks invoking <var>C</var>, <var>C</var> will see the value set in <var>A</var>, even
  49. if <var>B</var> used a nested <code>&lt;property&gt;</code> element as well.</p>
  50. <p>References to data types can also be passed to the new project, but by default they are not. If
  51. you set the <var>inheritrefs</var> attribute to <q>true</q>, all references will be copied, but they
  52. will not override references defined in the new project.</p>
  53. <p>Nested <a href="#reference"><code>&lt;reference&gt;</code></a> elements can also be used to copy
  54. references from the calling project to the new project, optionally under a different <var>id</var>.
  55. References taken from nested elements will override existing references that have been defined
  56. outside of targets in the new project&mdash;but not those defined inside of targets.</p>
  57. <h3>Parameters</h3>
  58. <table class="attr">
  59. <tr>
  60. <th>Attribute</th>
  61. <th>Description</th>
  62. <th>Required</th>
  63. </tr>
  64. <tr>
  65. <td>antfile</td>
  66. <td>the buildfile to use. This file is expected to be a filename relative to the <var>dir</var>
  67. attribute given.</td>
  68. <td>No; defaults to <q>build.xml</q></td>
  69. </tr>
  70. <tr>
  71. <td>dir</td>
  72. <td>the directory to use as a <var>basedir</var> for the new Ant project
  73. (unless <var>useNativeBasedir</var> is set to <q>true</q>). This will override
  74. the <var>basedir</var> setting of the called project.<br/> Also serves as the directory to
  75. resolve the <var>antfile</var> and <var>output</var> attribute's values (if any).
  76. </td>
  77. <td>No; defaults to the current project's <var>basedir</var>, unless <var>inheritall</var> has
  78. been set to <q>false</q>, in which case it doesn't have a default value</td>
  79. </tr>
  80. <tr>
  81. <td>target</td>
  82. <td>the target of the new Ant project that should be executed.</td>
  83. <td>No; defaults to the new project's default target</td>
  84. </tr>
  85. <tr>
  86. <td>output</td>
  87. <td>Filename to write the Ant output to. This is relative to the value of the <var>dir</var>
  88. attribute if it has been set or to the <var>basedir</var> of the current project otherwise.
  89. </td>
  90. <td>No</td>
  91. </tr>
  92. <tr>
  93. <td>inheritAll</td>
  94. <td>If <q>true</q>, pass all properties to the new Ant project.</td>
  95. <td>No; defaults to <q>true</q></td>
  96. </tr>
  97. <tr>
  98. <td>inheritRefs</td>
  99. <td>If <q>true</q>, pass all references to the new Ant project.</td>
  100. <td>No; defaults to <q>false</q></td>
  101. </tr>
  102. <tr>
  103. <td>useNativeBasedir</td>
  104. <td>If set to <q>true</q>, the child build will use the same <var>basedir</var> as it would have
  105. used when run from the command line (i.e. the <var>basedir</var> one would expect when looking
  106. at the child build's buildfile). <em>Since Ant 1.8.0</em></td>
  107. <td>No; defaults to <q>false</q></td>
  108. </tr>
  109. </table>
  110. <h3>Parameters specified as nested elements</h3>
  111. <h4>property</h4>
  112. <p>See the description of the <a href="property.html">property</a> task.<br/> These properties
  113. become equivalent to properties you define on the command line. These are special properties and
  114. they will always get passed down, even through additional <code>&lt;*ant*&gt;</code> tasks
  115. with <var>inheritAll</var> set to <q>false</q> (see above).<br/> Note that the <var>refid</var>
  116. attribute points to a reference in the calling project, not in the new one.</p>
  117. <h4 id="reference">reference</h4>
  118. <p>Used to choose references that shall be copied into the new project, optionally changing
  119. their <var>id</var>.</p>
  120. <table class="attr">
  121. <tr>
  122. <th>Attribute</th>
  123. <th>Description</th>
  124. <th>Required</th>
  125. </tr>
  126. <tr>
  127. <td>refid</td>
  128. <td>The <var>id</var> of the reference in the calling project.</td>
  129. <td>Yes</td>
  130. </tr>
  131. <tr>
  132. <td>torefid</td>
  133. <td>The <var>id</var> of the reference in the new project.</td>
  134. <td>No; defaults to the value of <var>refid</var></td>
  135. </tr>
  136. </table>
  137. <h4>propertyset</h4>
  138. <p><em>Since Ant 1.6</em>.</p>
  139. <p>You can specify a set of properties to be copied into the new project
  140. with <a href="../Types/propertyset.html">propertyset</a>s.</p>
  141. <h4>target</h4>
  142. <p><em>Since Ant 1.6.3</em>.</p>
  143. <p>You can specify multiple targets using nested <code>&lt;target&gt;</code> elements instead of
  144. using the <var>target</var> attribute. These will be executed as if Ant had been invoked with a
  145. single target whose dependencies are the targets so specified, in the order specified.</p>
  146. <table class="attr">
  147. <tr>
  148. <th>Attribute</th>
  149. <th>Description</th>
  150. <th>Required</th>
  151. </tr>
  152. <tr>
  153. <td>name</td>
  154. <td>The name of the called target.</td>
  155. <td>Yes</td>
  156. </tr>
  157. </table>
  158. <h3>Basedir of the new project</h3>
  159. <p>If you set <var>useNativeBasedir</var> to true, the <var>basedir</var> of the new project will be
  160. whatever the <var>basedir</var> attribute of the <code>&lt;project&gt;</code> element of the new
  161. project says (or the new project's directory if the there is no <var>basedir</var>
  162. attribute)&mdash;no matter what any other attribute of this task says and no matter how deeply
  163. nested into levels of <code>&lt;ant&gt;</code> invocations this task lives.</p>
  164. <p>If you haven't set <var>useNativeBasedir</var> or set it to <q>false</q>, the following rules
  165. apply:</p>
  166. <p>The <var>basedir</var> value of the new project is affected by the two attributes, <var>dir</var>
  167. and <var>inheritall</var>, as well as the <code>&lt;ant&gt;</code> task's history. The current
  168. behaviour is known to be confusing but cannot be changed without breaking backwards compatibility in
  169. subtle ways.</p>
  170. <p>If the <code>&lt;ant&gt;</code> task is in a "top level" build file, i.e. the project containing
  171. the <code>&lt;ant&gt;</code> task has not itself been invoked as part of a
  172. different <code>&lt;ant&gt;</code> (or <code>&lt;antcall&gt;</code>) task "higher up", the following
  173. table shows the details:</p>
  174. <table>
  175. <tr>
  176. <th><var>dir</var> attribute</th>
  177. <th><var>inheritAll</var> attribute</th>
  178. <th>new project's <var>basedir</var></th>
  179. </tr>
  180. <tr>
  181. <td>value provided</td>
  182. <td><q>true</q></td>
  183. <td>value of <var>dir</var> attribute</td>
  184. </tr>
  185. <tr>
  186. <td>value provided</td>
  187. <td><q>false</q></td>
  188. <td>value of <var>dir</var> attribute</td>
  189. </tr>
  190. <tr>
  191. <td>omitted</td>
  192. <td><q>true</q></td>
  193. <td><var>basedir</var> of calling project (the one whose build
  194. file contains the <code>&lt;ant&gt;</code> task).</td>
  195. </tr>
  196. <tr>
  197. <td>omitted</td>
  198. <td><q>false</q></td>
  199. <td><var>basedir</var> attribute of the <code>&lt;project&gt;</code> element
  200. of the new project</td>
  201. </tr>
  202. </table>
  203. <p>If on the other hand the <code>&lt;ant&gt;</code> task is already nested into another invocation,
  204. the parent invocation's settings affect the outcome of the <var>basedir</var> value. The current
  205. task's <var>dir</var> attribute will always win, but if the <var>dir</var> attribute has been
  206. omitted an even more complex situation arises:</p>
  207. <table>
  208. <tr>
  209. <th>parent <var>dir</var> attribute</th>
  210. <th>parent <var>inheritAll</var> attribute</th>
  211. <th>current <var>inheritAll</var> attribute</th>
  212. <th>new project's <var>basedir</var></th>
  213. </tr>
  214. <tr>
  215. <td>value provided</td>
  216. <td>any</td>
  217. <td>any</td>
  218. <td>value of parent's <var>dir</var> attribute</td>
  219. </tr>
  220. <tr>
  221. <td>omitted</td>
  222. <td><q>true</q></td>
  223. <td><q>true</q></td>
  224. <td><var>basedir</var> of parent project (the one whose build file called the build file that
  225. contains the current <code>&lt;ant&gt;</code> task).</td>
  226. </tr>
  227. <tr>
  228. <td>omitted</td>
  229. <td><q>true</q></td>
  230. <td><q>false</q></td>
  231. <td><var>basedir</var> of parent project (the one whose build file called the build file that
  232. contains the current <code>&lt;ant&gt;</code> task).</td>
  233. </tr>
  234. <tr>
  235. <td>omitted</td>
  236. <td><q>false</q></td>
  237. <td><q>true</q></td>
  238. <td><var>basedir</var> of calling project (the one whose build file contains the
  239. current <code>&lt;ant&gt;</code> task).</td>
  240. </tr>
  241. <tr>
  242. <td>omitted</td>
  243. <td><q>false</q></td>
  244. <td><q>false</q></td>
  245. <td><var>basedir</var> attribute of the <code>&lt;project&gt;</code> element of the new
  246. project</td>
  247. </tr>
  248. </table>
  249. <p>If you add even deeper levels of nesting, things get even more complicated and you need to apply
  250. the above table recursively.</p>
  251. <p>If the <var>basedir</var> of the outermost build has been specified as a property on the command
  252. line (i.e. <code>-Dbasedir=some-value</code> or a <code>-propertyfile</code> argument) the value
  253. provided will get an even higher priority. For any <code>&lt;ant&gt;</code> task that doesn't
  254. specify a <var>dir</var> attribute, the new project's <var>basedir</var> will be the value specified
  255. on the command line&mdash;no matter how deeply nested into layers of build files the task may
  256. be.</p>
  257. <p>The same happens if the <var>basedir</var> is specified as a nested <code>&lt;property&gt;</code>
  258. of an <code>&lt;ant&gt;</code> task. The <var>basedir</var> of build files started at deeper levels
  259. will be set to the specified value of the property element unless the corresponding Ant tasks set
  260. the <var>dir</var> attribute explicitly.</p>
  261. <h3>Examples</h3>
  262. <pre>
  263. &lt;ant antfile=&quot;subproject/subbuild.xml&quot; target=&quot;compile&quot;/&gt;
  264. &lt;ant dir=&quot;subproject&quot;/&gt;
  265. &lt;ant antfile=&quot;subproject/property_based_subbuild.xml&quot;&gt;
  266. &lt;property name=&quot;param1&quot; value=&quot;version 1.x&quot;/&gt;
  267. &lt;property file=&quot;config/subproject/default.properties&quot;/&gt;
  268. &lt;/ant&gt;
  269. &lt;ant inheritAll=&quot;false&quot; antfile=&quot;subproject/subbuild.xml&quot;&gt;
  270. &lt;property name=&quot;output.type&quot; value=&quot;html&quot;/&gt;
  271. &lt;/ant&gt;</pre>
  272. <p>These lines invoke the same build file:</p>
  273. <pre>
  274. &lt;ant antfile=&quot;sub1/sub2/build.xml&quot;/&gt;
  275. &lt;ant antfile=&quot;sub2/build.xml&quot; dir=&quot;sub1&quot;/&gt;
  276. &lt;ant antfile=&quot;build.xml&quot; dir=&quot;sub1/sub2&quot;/&gt;</pre>
  277. <p>The build file of the calling project defines some <code>&lt;path&gt;</code> elements like
  278. this:</p>
  279. <pre>
  280. &lt;path id="path1"&gt;
  281. ...
  282. &lt;/path&gt;
  283. &lt;path id="path2"&gt;
  284. ...
  285. &lt;/path&gt;</pre>
  286. <p>and the called build file (<samp>subbuild.xml</samp>) also defines a <code>&lt;path&gt;</code>
  287. with the <var>id</var> <samp>path1</samp>, but <samp>path2</samp> is not defined:</p>
  288. <pre>&lt;ant antfile=&quot;subbuild.xml&quot; inheritrefs=&quot;true&quot;/&gt;</pre>
  289. <p>will not override <samp>subbuild</samp>'s definition of <samp>path1</samp>, but make the parent's
  290. definition of <samp>path2</samp> available in the <samp>subbuild</samp>.</p>
  291. <pre>&lt;ant antfile=&quot;subbuild.xml&quot;/&gt;</pre>
  292. <p>as well as</p>
  293. <pre>&lt;ant antfile=&quot;subbuild.xml&quot; inheritrefs=&quot;false&quot;/&gt;</pre>
  294. <p>will neither override <samp>path1</samp> nor copy <samp>path2</samp>.</p>
  295. <pre>
  296. &lt;ant antfile=&quot;subbuild.xml&quot; inheritrefs=&quot;false&quot;&gt;
  297. &lt;reference refid=&quot;path1&quot;/&gt;
  298. &lt;/ant&gt;</pre>
  299. <p>will override <samp>subbuild</samp>'s definition of <samp>path1</samp>.</p>
  300. <pre>
  301. &lt;ant antfile=&quot;subbuild.xml&quot; inheritrefs=&quot;false&quot;&gt;
  302. &lt;reference refid=&quot;path1&quot; torefid=&quot;path2&quot;/&gt;
  303. &lt;/ant&gt;</pre>
  304. <p>will copy the parent's definition of <samp>path1</samp> into the new project using
  305. the <var>id</var> <samp>path2</samp>.</p>
  306. </body>
  307. </html>