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 15 KiB

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