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