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.

depend.html 8.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  5. <title>Depend Task</title>
  6. </head>
  7. <body>
  8. <h2>Depend</h2>
  9. A task to manage Java class file dependencies.
  10. <h3>Description</h3>
  11. <p>
  12. The depend task works by determining which classes are out of date with
  13. respect to their source and then removing the class files of any other
  14. classes which depend on the out-of-date classes.
  15. </p>
  16. <p> To determine the class dependencies, the depend task analyses the class
  17. files of all class files passed to it. Depend does not parse your source code in
  18. any way but relies upon the class references encoded into the class files by the
  19. compiler. This is generally faster than parsing the Java source.</p>
  20. <p>
  21. To learn more about how this information is obtained from the class files,
  22. please refer to <a href="http://java.sun.com/docs/books/vmspec/">the Java
  23. Virtual Machine Specification</a>
  24. </p>
  25. <p> Since a class' dependencies only change when the class itself changes, the
  26. depend task is able to cache dependency information. Only those class files
  27. which have changed will have their dependency information re-analysed. Note that
  28. if you change a class' dependencies by changing the source, it will be
  29. recompiled anyway. You can examine the dependency files created to understand
  30. the dependencies of your classes. Please do not rely, however, on the format of
  31. the information, as it may change in a later release. </p>
  32. <p> Once depend discovers all of the class dependencies, it &quot;inverts&quot;
  33. this relation to determine, for each class, which other classes are dependent
  34. upon it. This &quot;affects&quot; list is used to discover which classes are
  35. invalidated by the out of date class. The class files of the invalidated
  36. classes are removed, triggering the compilation of the affected classes. </p>
  37. <p> The depend task supports an attribute, &quot;closure&quot; which controls
  38. whether depend will only consider direct class-class relationships or whether it
  39. will also consider transitive, indirect relationships. For example, say there
  40. are three classes, A, which depends on B, which in-turn depend on C. Now say
  41. that class C is out of date. Without closure, only class B would be removed by
  42. depend. With closure set, class A would also be removed. Normally direct
  43. relationships are sufficient - it is unusual for a class to depend on another
  44. without having a direct relationship. With closure set, you will notice that
  45. depend typically removes far more class files. </p>
  46. <p>The classpath attribute for <code>&lt;depend&gt;</code> is optional. If it is present,
  47. depend will check class dependencies against classes and jars on this classpath.
  48. Any classes which depend on an element from this classpath and which are older
  49. than that element will be deleted. A typical example where you would use this
  50. facility would be where you are building a utility jar and want to make sure
  51. classes which are out of date with respect to this jar are rebuilt. You should
  52. <b>not</b> include jars in this classpath which you do not expect to change,
  53. such as the JDK runtime jar or third party jars, since doing so will just slow
  54. down the dependency check. This means that if you do use a classpath for the
  55. depend task it may be different from the classpath necessary to actually
  56. compile your code.</p>
  57. <h3>Performance</h3>
  58. <p> The performance of the depend task is dependent on a
  59. number of factors such as class relationship complexity and how many class files
  60. are out of date. The decision about whether it is cheaper to just recompile all
  61. classes or to use the depend task will depend on the size of your project and
  62. how interrelated your classes are. </p>
  63. <h3>Limitations</h3>
  64. <p> There are some source dependencies which depend will not detect. </p>
  65. <ul>
  66. <li>If the Java compiler optimizes away a class relationship,
  67. there can be a source dependency without a class dependency. </li>
  68. <li>Non public classes cause two problems. Firstly depend cannot relate
  69. the class file to a source file. In the future this may be addressed
  70. using the source file attribute in the classfile. Secondly, neither
  71. depend nor the compiler tasks can detect when a non public class is
  72. missing. Inner classes are handled by the depend task.</li>
  73. </ul>
  74. The most obvious example of these limitations is that the task can't tell
  75. which classes to recompile when a constant primitive data type exported
  76. by other classes is changed. For example, a change in the definition of
  77. something like
  78. <pre>
  79. public final class Constants {
  80. public final static boolean DEBUG=false;
  81. }
  82. </pre> will not be picked up by other classes.
  83. <h3>Parameters</h3>
  84. <table border="1" cellpadding="2" cellspacing="0">
  85. <tr>
  86. <td valign="top"><b>Attribute</b></td>
  87. <td valign="top"><b>Description</b></td>
  88. <td align="center" valign="top"><b>Required</b></td>
  89. </tr>
  90. <tr>
  91. <td valign="top">srcDir</td>
  92. <td valign="top">This is the directory where the source exists. depend
  93. will examine this to determine which classes are out of date. If you use multiple
  94. source directories you can pass this attribute a path of source directories.</td>
  95. <td valign="top" align="center">Yes</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">destDir</td>
  99. <td valign="top">This is the root directory of the class files which
  100. will be analysed. If this is not present, the srcdir is used.</td>
  101. <td valign="top" align="center">No</td>
  102. </tr>
  103. <tr>
  104. <td valign="top">cache</td>
  105. <td valign="top">This is a directory in which depend can store and
  106. retrieve dependency information. If this is not present, depend will not
  107. use a cache </td>
  108. <td valign="top" align="center">No</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">closure</td>
  112. <td valign="top">This attribute controls whether depend only removes
  113. classes which directly depend on out of date classes. If this is set to true,
  114. depend will traverse the class dependency graph deleting all affected
  115. classes. Defaults to false</td>
  116. <td valign="top" align="center">No</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">dump</td>
  120. <td valign="top">If true the dependency information will be written to the debug level log
  121. </td>
  122. <td valign="top" align="center">No</td>
  123. </tr>
  124. <tr>
  125. <td valign="top">classpath</td>
  126. <td valign="top">The classpath containing jars and classes for which <code>&lt;depend&gt;</code> should also
  127. check dependencies</td>
  128. <td valign="top" align="center">No</td>
  129. </tr>
  130. <tr>
  131. <td valign="top">warnOnRmiStubs</td>
  132. <td valign="top">Flag to disable warnings about files that look like rmic generated stub/skeleton
  133. classes, and which have no .java source. Useful when doing rmi development. </td>
  134. <td valign="top" align="center">No, default=true</td>
  135. </tr>
  136. </table>
  137. <h3>Parameters specified as nested elements</h3>
  138. <p>The <code>depend</code> task's <code>classpath</code> attribute is a
  139. <a href="../using.html#path">PATH-like structure</a> and can also be set
  140. via a nested <code>&lt;classpath&gt;</code> element.</p>
  141. <p>Additionally,
  142. this task forms an implicit
  143. <a href="../CoreTypes/fileset.html">FileSet</a>
  144. and supports all attributes of
  145. <code>&lt;fileset&gt;</code> (<code>dir</code> becomes <code>srcdir</code>),
  146. as well as the nested <code>&lt;include&gt;</code>,
  147. <code>&lt;exclude&gt;</code>, and <code>&lt;patternset&gt;</code> elements.
  148. <h3>Examples</h3>
  149. <pre>&lt;depend srcdir=&quot;${java.dir}&quot;
  150. destdir=&quot;${build.classes}&quot;
  151. cache=&quot;depcache&quot;
  152. closure=&quot;yes&quot;/&gt;</pre>
  153. <p>removes any classes in the <code>${build.classes}</code> directory
  154. that depend on out-of-date classes. Classes are considered out-of-date with
  155. respect to the source in the <code>${java.dir}</code> directory, using the same
  156. mechanism as the <code>&lt;javac&gt;</code> task. In this example, the
  157. <code>&lt;depend&gt;</code> task caches its dependency
  158. information in the <code>depcache</code> directory. </p>
  159. <pre>
  160. &lt;depend srcdir=&quot;${java.dir}&quot; destdir=&quot;${build.classes}&quot;
  161. cache=&quot;depcache&quot; closure=&quot;yes&quot;&gt;
  162. &lt;include name=&quot;**/*.java&quot;/&gt;
  163. &lt;excludesfile name=&quot;${java.dir}/build_excludes&quot;/&gt;
  164. &lt;/depend&gt;
  165. </pre>
  166. <p>does the same as the previous example, but explicitly includes all
  167. <code>.java</code> files, except those that match the list given
  168. in <code>${java.dir}/build_excludes</code>.</p>
  169. <hr>
  170. <p align="center">Copyright &copy; 2001-2002,2004-2005 The Apache Software Foundation.
  171. All rights Reserved.</p>
  172. </body>
  173. </html>