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 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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><a name="ant">Ant</a></h2>
  23. <h3>Description</h3>
  24. <p>Runs Ant on a supplied buildfile. This can be used to build
  25. subprojects. <strong>This task must not be used outside of a
  26. <code>target</code> if it invokes the same build file it is part
  27. of.</strong></p>
  28. <p>When the <i>antfile</i> attribute is omitted, the file &quot;build.xml&quot;
  29. in the supplied directory (<i>dir</i> attribute) is used.</p>
  30. <p>If no target attribute is supplied, the default target of the new project is
  31. used.</p>
  32. <p>By default, all of the properties of the current project will be
  33. available in the new project. Alternatively, you can set the
  34. <i>inheritAll</i> attribute to <code>false</code> and only
  35. &quot;user&quot; properties (i.e., those passed on the command-line)
  36. will be passed to the new project. In either case, the set of
  37. properties passed to the new project will override the properties that
  38. are set in the new project (See also the <a
  39. href="property.html">property task</a>).</p>
  40. <p>You can also set properties in the new project from the old project
  41. by using nested property tags. These properties are always passed
  42. to the new project and any project created in that project
  43. regardless of the setting of <i>inheritAll</i>. This allows you to
  44. parameterize your subprojects. Properties defined on the command line
  45. cannot be overridden by nested <code>&lt;property&gt;</code> elements.</p>
  46. <p>References to data types can also be passed to the new project, but
  47. by default they are not. If you set the inheritrefs attribute to
  48. true, all references will be copied, but they will not override
  49. references defined in the new project.</p>
  50. <p>Nested <a href="#reference"><i><code>&lt;reference&gt;</code></i></a> elements
  51. can also be used to copy references from the calling project to the
  52. new project, optionally under a different id. References taken from
  53. nested elements will override existing references that have been
  54. defined outside of targets in the new project - but not those defined
  55. inside of targets.</p>
  56. <h3>Parameters</h3>
  57. <table border="1" cellpadding="2" cellspacing="0">
  58. <tr>
  59. <td valign="top"><b>Attribute</b></td>
  60. <td valign="top"><b>Description</b></td>
  61. <td align="center" valign="top"><b>Required</b></td>
  62. </tr>
  63. <tr>
  64. <td valign="top">antfile</td>
  65. <td valign="top">the buildfile to use. Defaults to
  66. &quot;build.xml&quot;. This file is expected to be a filename
  67. relative to the dir attribute given.</td>
  68. <td valign="top" align="center">No</td>
  69. </tr>
  70. <tr>
  71. <td valign="top">dir</td>
  72. <td valign="top">the directory to use as a basedir for the new Ant project.
  73. Defaults to the current project's basedir, unless
  74. inheritall has been set to false, in which case it doesn't
  75. have a default value. This will override the basedir
  76. setting of the called project.<br/>
  77. Also serves as the directory to resolve the antfile and output
  78. attribute's values (if any).
  79. </td>
  80. <td valign="top" align="center">No</td>
  81. </tr>
  82. <tr>
  83. <td valign="top">target</td>
  84. <td valign="top">the target of the new Ant project that should be executed.
  85. Defaults to the new project's default target.</td>
  86. <td valign="top" align="center">No</td>
  87. </tr>
  88. <tr>
  89. <td valign="top">output</td>
  90. <td valign="top">Filename to write the ant output to. This is
  91. relative to the value of the dir attribute if it has been set or
  92. to the base directory of the current project otherwise.
  93. </td>
  94. <td align="center" valign="top">No</td>
  95. </tr>
  96. <tr>
  97. <td valign="top">inheritAll</td>
  98. <td valign="top">If <code>true</code>, pass all properties to the
  99. new Ant project. Defaults to <code>true</code>.</td>
  100. <td align="center" valign="top">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">inheritRefs</td>
  104. <td valign="top">If <code>true</code>, pass all references to the
  105. new Ant project. Defaults to <code>false</code>.</td>
  106. <td align="center" valign="top">No</td>
  107. </tr>
  108. </table>
  109. <h3>Parameters specified as nested elements</h3>
  110. <h4>property</h4>
  111. <p>See the description of the <a href="property.html">property
  112. task</a>. <br>
  113. These properties become equivalent to properties you define on
  114. the command line. These are special properties and they will always get passed
  115. down, even through additional <code>&lt;*ant*&gt;</code> tasks with inheritall set to
  116. false (see above). <br>
  117. Note that the <code>refid</code> attribute points to a
  118. reference in the calling project, not in the new one.</p>
  119. <h4><a name="reference">reference</a></h4>
  120. <p>Used to choose references that shall be copied into the new project,
  121. optionally changing their id.</p>
  122. <table border="1" cellpadding="2" cellspacing="0">
  123. <tr>
  124. <td valign="top"><b>Attribute</b></td>
  125. <td valign="top"><b>Description</b></td>
  126. <td align="center" valign="top"><b>Required</b></td>
  127. </tr>
  128. <tr>
  129. <td valign="top">refid</td>
  130. <td valign="top">The id of the reference in the calling project.</td>
  131. <td valign="top" align="center">Yes</td>
  132. </tr>
  133. <tr>
  134. <td valign="top">torefid</td>
  135. <td valign="top">The id of the reference in the new project.</td>
  136. <td valign="top" align="center">No, defaults to the value of refid.</td>
  137. </tr>
  138. </table>
  139. <h4>propertyset</h4>
  140. <p>You can specify a set of properties to be copied into the new
  141. project with <a
  142. href="../CoreTypes/propertyset.html">propertyset</a>s.</p>
  143. <p><em>since Ant 1.6</em>.</p>
  144. <h4>target</h4>
  145. <p>You can specify multiple targets using nested <code>&lt;target&gt;</code> elements
  146. instead of using the target attribute. These will be executed as if
  147. Ant had been invoked with a single target whose dependencies are the
  148. targets so specified, in the order specified.</p>
  149. <table border="1" cellpadding="2" cellspacing="0">
  150. <tr>
  151. <td valign="top"><b>Attribute</b></td>
  152. <td valign="top"><b>Description</b></td>
  153. <td align="center" valign="top"><b>Required</b></td>
  154. </tr>
  155. <tr>
  156. <td valign="top">name</td>
  157. <td valign="top">The name of the called target.</td>
  158. <td valign="top" align="center">Yes</td>
  159. </tr>
  160. </table>
  161. <p><em>since Ant 1.6.3</em>.</p>
  162. <h3>Basedir of the new project</h3>
  163. <p>The basedir value of the new project is affected by the two
  164. attributes dir and inheritall as well as
  165. the <code>&lt;ant&gt;</code> task's history. The current behaviour
  166. is known to be confusing but cannot be changed without breaking
  167. backwards compatibility in subtle ways.</p>
  168. <p>If the <code>&lt;ant&gt;</code> task is in a "top level" build
  169. file, i.e. the project containing the <code>&lt;ant&gt;</code> task
  170. has not itself been invoked as part of a
  171. different <code>&lt;ant&gt;</code> (or <code>&lt;antcall&gt;</code>)
  172. task "higher up", the following table shows the details:</p>
  173. <table border="1" cellpadding="2" cellspacing="0">
  174. <tr>
  175. <td valign="top"><b>dir attribute</b></td>
  176. <td valign="top"><b>inheritAll attribute</b></td>
  177. <td valign="top"><b>new project's basedir</b></td>
  178. </tr>
  179. <tr>
  180. <td valign="top">value provided</td>
  181. <td valign="top">true</td>
  182. <td valign="top">value of dir attribute</td>
  183. </tr>
  184. <tr>
  185. <td valign="top">value provided</td>
  186. <td valign="top">false</td>
  187. <td valign="top">value of dir attribute</td>
  188. </tr>
  189. <tr>
  190. <td valign="top">omitted</td>
  191. <td valign="top">true</td>
  192. <td valign="top">basedir of calling project (the one whose build
  193. file contains the <code>&lt;ant&gt;</code> task).</td>
  194. </tr>
  195. <tr>
  196. <td valign="top">omitted</td>
  197. <td valign="top">false</td>
  198. <td valign="top">basedir attribute of the <code>&lt;project&gt;</code> element
  199. of the new project</td>
  200. </tr>
  201. </table>
  202. <p>If on the other hand the <code>&lt;ant&gt;</code> task is already
  203. nested into another invocation, the parent invocation's settings
  204. affect the outcome of the basedir value. The current task's dir
  205. attribute will always win, but if the dir attribute has been omitted
  206. an even more complex situation arises:</p>
  207. <table border="1" cellpadding="2" cellspacing="0">
  208. <tr>
  209. <td valign="top"><b>parent dir attribute</b></td>
  210. <td valign="top"><b>parent inheritAll attribute</b></td>
  211. <td valign="top"><b>current inheritAll attribute</b></td>
  212. <td valign="top"><b>new project's basedir</b></td>
  213. </tr>
  214. <tr>
  215. <td valign="top">value provided</td>
  216. <td valign="top">any</td>
  217. <td valign="top">any</td>
  218. <td valign="top">value of parent's dir attribute</td>
  219. </tr>
  220. <tr>
  221. <td valign="top">omitted</td>
  222. <td valign="top">true</td>
  223. <td valign="top">true</td>
  224. <td valign="top">basedir of parent project (the one whose build
  225. file called the build file that contains
  226. the current <code>&lt;ant&gt;</code> task).</td>
  227. </tr>
  228. <tr>
  229. <td valign="top">omitted</td>
  230. <td valign="top">true</td>
  231. <td valign="top">false</td>
  232. <td valign="top">basedir of parent project (the one whose build
  233. file called the build file that contains
  234. the current <code>&lt;ant&gt;</code> task).</td>
  235. </tr>
  236. <tr>
  237. <td valign="top">omitted</td>
  238. <td valign="top">false</td>
  239. <td valign="top">true</td>
  240. <td valign="top">basedir of calling project (the one whose build
  241. file contains the current <code>&lt;ant&gt;</code> task).</td>
  242. </tr>
  243. <tr>
  244. <td valign="top">omitted</td>
  245. <td valign="top">false</td>
  246. <td valign="top">false</td>
  247. <td valign="top">basedir attribute of the <code>&lt;project&gt;</code> element
  248. of the new project</td>
  249. </tr>
  250. </table>
  251. <p>If you add even deeper levels of nesting, things get even more
  252. complicated and you need to apply the above table recursively.</p>
  253. <p>If the basedir of the outer most build has been specified as a
  254. property on the command line (i.e. <code>-Dbasedir=some-value</code>
  255. or a <code>-propertyfile</code> argument) the value provided will
  256. get an even higher priority. For any <code>&lt;ant&gt;</code> task
  257. that doesn't specify a dir attribute, the new project's basedir will
  258. be the value specified on the command line - no matter how deeply
  259. nested into layers of build files the task may be.</p>
  260. <p>The samae happens if the basedir is specified as a
  261. nested <code>&lt;property&gt;</code> of an <code>&lt;ant&gt;</code>
  262. task. The basedir of build files started at deeper levels will be
  263. set to the specified value of the property element unless the
  264. corresponding Ant tasks set the dir attribute explicitly.</p>
  265. <h3>Examples</h3>
  266. <blockquote><pre>
  267. &lt;ant antfile=&quot;subproject/subbuild.xml&quot; target=&quot;compile&quot;/&gt;
  268. &lt;ant dir=&quot;subproject&quot;/&gt;
  269. &lt;ant antfile=&quot;subproject/property_based_subbuild.xml&quot;&gt;
  270. &lt;property name=&quot;param1&quot; value=&quot;version 1.x&quot;/&gt;
  271. &lt;property file=&quot;config/subproject/default.properties&quot;/&gt;
  272. &lt;/ant&gt;
  273. &lt;ant inheritAll=&quot;false&quot; antfile=&quot;subproject/subbuild.xml&quot;&gt;
  274. &lt;property name=&quot;output.type&quot; value=&quot;html&quot;/&gt;
  275. &lt;/ant&gt;
  276. </pre></blockquote>
  277. <p>These lines invoke the same build file:</p>
  278. <blockquote><pre>
  279. &lt;ant antfile=&quot;sub1/sub2/build.xml&quot; /&gt;
  280. &lt;ant antfile=&quot;sub2/build.xml&quot; dir=&quot;sub1&quot; /&gt;
  281. &lt;ant antfile=&quot;build.xml&quot; dir=&quot;sub1/sub2&quot; /&gt;
  282. </pre></blockquote>
  283. <p>The build file of the calling project defines some
  284. <code>&lt;path&gt;</code> elements like this:</p>
  285. <blockquote><pre>
  286. &lt;path id="path1"&gt;
  287. ...
  288. &lt;/path&gt;
  289. &lt;path id="path2"&gt;
  290. ...
  291. &lt;/path&gt;
  292. </pre></blockquote>
  293. <p>and the called build file (<code>subbuild.xml</code>) also defines
  294. a <code>&lt;path&gt;</code> with the id <code>path1</code>, but
  295. <code>path2</code> is not defined:</p>
  296. <blockquote><pre>
  297. &lt;ant antfile=&quot;subbuild.xml&quot; inheritrefs=&quot;true&quot;/&gt;
  298. </pre></blockquote>
  299. <p>will not override <code>subbuild</code>'s definition of
  300. <code>path1</code>, but make the parent's definition of
  301. <code>path2</code> available in the subbuild.</p>
  302. <blockquote><pre>
  303. &lt;ant antfile=&quot;subbuild.xml&quot;/&gt;
  304. </pre></blockquote>
  305. <p>as well as</p>
  306. <blockquote><pre>
  307. &lt;ant antfile=&quot;subbuild.xml&quot; inheritrefs=&quot;false&quot;/&gt;
  308. </pre></blockquote>
  309. <p>will neither override <code>path1</code> nor copy
  310. <code>path2</code>.</p>
  311. <blockquote><pre>
  312. &lt;ant antfile=&quot;subbuild.xml&quot; inheritrefs=&quot;false&quot;&gt;
  313. &lt;reference refid=&quot;path1&quot;/&gt;
  314. &lt;/ant&gt;
  315. </pre></blockquote>
  316. <p>will override <code>subbuild</code>'s definition of
  317. <code>path1</code>.</p>
  318. <blockquote><pre>
  319. &lt;ant antfile=&quot;subbuild.xml&quot; inheritrefs=&quot;false&quot;&gt;
  320. &lt;reference refid=&quot;path1&quot; torefid=&quot;path2&quot;/&gt;
  321. &lt;/ant&gt;
  322. </pre></blockquote>
  323. <p>will copy the parent's definition of <code>path1</code> into the
  324. new project using the id <code>path2</code>.</p>
  325. </body>
  326. </html>