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

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