Mit Java 8 wird im bin Verzeichnis auch das JDeps Tool ausgeliefert. Dieses Tool ermöglicht eine statische Kodeanalyse von der Kommandozeile. Es kann die statischen Abhängigkeiten von Klassen und Jars aufzeigen und auch eine Abhängigkeitsgraphen generieren. So ist man dann für Java 9 vorbereitet.
Das wollen wir einmal ausprobieren. Dazu hole ich mir für mein Testprojekt erst einmal alle Jars und untersuche dann das JUnit 4.12.
Also in der pom.xml folgendes Plugin ergänze und ein „mvn package“ ausführen:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.0.1</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> |
So dann haben wir diese Jars:
Wir schauen uns nun mal kurz die Onlinehilfe zu dem Tool mit jdeps -h an:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
Usage: jdeps <options> <classes...> where <classes> can be a pathname to a .class file, a directory, a JAR file, or a fully-qualified class name. Possible options include: -dotoutput <dir> Destination directory for DOT file output -s -summary Print dependency summary only -v -verbose Print all class level dependencies Equivalent to -verbose:class -filter:none. -verbose:package Print package-level dependencies excluding dependencies within the same package by default -verbose:class Print class-level dependencies excluding dependencies within the same package by default -cp <path> -classpath <path> Specify where to find class files -p <pkgname> -package <pkgname> Finds dependences matching the given package name (may be given multiple times) -e <regex> -regex <regex> Finds dependences matching the given pattern (-p and -e are exclusive) -f <regex> -filter <regex> Filter dependences matching the given pattern If given multiple times, the last one will be used. -filter:package Filter dependences within the same package (default) -filter:archive Filter dependences within the same archive -filter:none No -filter:package and -filter:archive filtering Filtering specified via the -filter option still applies. -include <regex> Restrict analysis to classes matching pattern This option filters the list of classes to be analyzed. It can be used together with -p and -e which apply pattern to the dependences -P -profile Show profile or the file containing a package -apionly Restrict analysis to APIs i.e. dependences from the signature of public and protected members of public classes including field type, method parameter types, returned type, checked exception types etc -R -recursive Recursively traverse all dependencies. The -R option implies -filter:none. If -p, -e, -f option is specified, only the matching dependences are analyzed. -jdkinternals Finds class-level dependences on JDK internal APIs. By default, it analyzes all classes on -classpath and input files unless -include option is specified. This option cannot be used with -p, -e and -s options. WARNING: JDK internal APIs may not be accessible in the next release. -version Version information |
Nun öffnen wir eine Kommandozeile im Verzeichnis target/alternateLocation und führen unter Java 1.8 den folgenden Befehl aus (hier Mac OS X). Den Punkt für das aktuelle Verzeichnis nicht vergessen.
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/jdeps -dotoutput . junit-4.12.jar
Als Ergebnis erhalten wir zwei Dateien. Die summary.dot
1 2 3 4 5 |
summary.dot digraph "summary" { "junit-4.12.jar" -> "not found"; "junit-4.12.jar" -> "rt.jar"; } |
und die unit-4.12.jar.dot mit allen Abhängigkeiten:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
digraph "junit-4.12.jar" { // Path: junit-4.12.jar "junit.extensions" -> "java.lang"; "junit.extensions" -> "junit.framework (junit-4.12.jar)"; "junit.framework" -> "java.io"; "junit.framework" -> "java.lang"; "junit.framework" -> "java.lang.annotation"; "junit.framework" -> "java.lang.reflect"; "junit.framework" -> "java.util"; "junit.framework" -> "org.junit (junit-4.12.jar)"; "junit.framework" -> "org.junit.internal (junit-4.12.jar)"; "junit.framework" -> "org.junit.runner (junit-4.12.jar)"; "junit.framework" -> "org.junit.runner.manipulation (junit-4.12.jar)"; "junit.framework" -> "org.junit.runner.notification (junit-4.12.jar)"; "junit.runner" -> "java.io"; "junit.runner" -> "java.lang"; "junit.runner" -> "java.lang.reflect"; "junit.runner" -> "java.text"; "junit.runner" -> "java.util"; "junit.runner" -> "junit.framework (junit-4.12.jar)"; "junit.textui" -> "java.io"; "junit.textui" -> "java.lang"; "junit.textui" -> "java.text"; "junit.textui" -> "java.util"; "junit.textui" -> "junit.framework (junit-4.12.jar)"; "junit.textui" -> "junit.runner (junit-4.12.jar)"; "org.junit" -> "java.lang"; "org.junit" -> "java.lang.annotation"; "org.junit" -> "java.util"; "org.junit" -> "org.hamcrest (not found)"; "org.junit" -> "org.junit.internal (junit-4.12.jar)"; "org.junit" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.experimental" -> "java.io"; "org.junit.experimental" -> "java.lang"; "org.junit.experimental" -> "java.util.concurrent"; "org.junit.experimental" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.experimental" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.experimental" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.experimental.categories" -> "java.lang"; "org.junit.experimental.categories" -> "java.lang.annotation"; "org.junit.experimental.categories" -> "java.util"; "org.junit.experimental.categories" -> "org.junit (junit-4.12.jar)"; "org.junit.experimental.categories" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.experimental.categories" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.experimental.categories" -> "org.junit.runner.manipulation (junit-4.12.jar)"; "org.junit.experimental.categories" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.experimental.categories" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.experimental.categories" -> "org.junit.validator (junit-4.12.jar)"; "org.junit.experimental.max" -> "java.io"; "org.junit.experimental.max" -> "java.lang"; "org.junit.experimental.max" -> "java.lang.annotation"; "org.junit.experimental.max" -> "java.util"; "org.junit.experimental.max" -> "junit.framework (junit-4.12.jar)"; "org.junit.experimental.max" -> "org.junit.internal.requests (junit-4.12.jar)"; "org.junit.experimental.max" -> "org.junit.internal.runners (junit-4.12.jar)"; "org.junit.experimental.max" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.experimental.max" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.experimental.max" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.experimental.max" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.experimental.results" -> "java.io"; "org.junit.experimental.results" -> "java.lang"; "org.junit.experimental.results" -> "java.util"; "org.junit.experimental.results" -> "org.hamcrest (not found)"; "org.junit.experimental.results" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.experimental.results" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.experimental.results" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.experimental.runners" -> "java.lang"; "org.junit.experimental.runners" -> "java.lang.reflect"; "org.junit.experimental.runners" -> "java.util"; "org.junit.experimental.runners" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.experimental.runners" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.experimental.theories" -> "java.lang"; "org.junit.experimental.theories" -> "java.lang.annotation"; "org.junit.experimental.theories" -> "java.lang.reflect"; "org.junit.experimental.theories" -> "java.util"; "org.junit.experimental.theories" -> "org.junit (junit-4.12.jar)"; "org.junit.experimental.theories" -> "org.junit.experimental.theories.internal (junit-4.12.jar)"; "org.junit.experimental.theories" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.experimental.theories" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.experimental.theories" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.experimental.theories.internal" -> "java.lang"; "org.junit.experimental.theories.internal" -> "java.lang.annotation"; "org.junit.experimental.theories.internal" -> "java.lang.reflect"; "org.junit.experimental.theories.internal" -> "java.util"; "org.junit.experimental.theories.internal" -> "org.junit (junit-4.12.jar)"; "org.junit.experimental.theories.internal" -> "org.junit.experimental.theories (junit-4.12.jar)"; "org.junit.experimental.theories.internal" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.experimental.theories.suppliers" -> "java.lang"; "org.junit.experimental.theories.suppliers" -> "java.lang.annotation"; "org.junit.experimental.theories.suppliers" -> "java.util"; "org.junit.experimental.theories.suppliers" -> "org.junit.experimental.theories (junit-4.12.jar)"; "org.junit.internal" -> "java.io"; "org.junit.internal" -> "java.lang"; "org.junit.internal" -> "java.lang.annotation"; "org.junit.internal" -> "java.lang.reflect"; "org.junit.internal" -> "java.text"; "org.junit.internal" -> "java.util"; "org.junit.internal" -> "org.hamcrest (not found)"; "org.junit.internal" -> "org.junit (junit-4.12.jar)"; "org.junit.internal" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.internal" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.internal" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.internal.builders" -> "java.lang"; "org.junit.internal.builders" -> "java.lang.annotation"; "org.junit.internal.builders" -> "java.lang.reflect"; "org.junit.internal.builders" -> "java.util"; "org.junit.internal.builders" -> "junit.framework (junit-4.12.jar)"; "org.junit.internal.builders" -> "org.junit (junit-4.12.jar)"; "org.junit.internal.builders" -> "org.junit.internal.runners (junit-4.12.jar)"; "org.junit.internal.builders" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.internal.builders" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.internal.builders" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.internal.builders" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.internal.matchers" -> "java.io"; "org.junit.internal.matchers" -> "java.lang"; "org.junit.internal.matchers" -> "java.lang.reflect"; "org.junit.internal.matchers" -> "org.hamcrest (not found)"; "org.junit.internal.matchers" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.internal.requests" -> "java.lang"; "org.junit.internal.requests" -> "java.util"; "org.junit.internal.requests" -> "org.junit.internal.builders (junit-4.12.jar)"; "org.junit.internal.requests" -> "org.junit.internal.runners (junit-4.12.jar)"; "org.junit.internal.requests" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.internal.requests" -> "org.junit.runner.manipulation (junit-4.12.jar)"; "org.junit.internal.runners" -> "java.lang"; "org.junit.internal.runners" -> "java.lang.annotation"; "org.junit.internal.runners" -> "java.lang.reflect"; "org.junit.internal.runners" -> "java.util"; "org.junit.internal.runners" -> "java.util.concurrent"; "org.junit.internal.runners" -> "junit.extensions (junit-4.12.jar)"; "org.junit.internal.runners" -> "junit.framework (junit-4.12.jar)"; "org.junit.internal.runners" -> "org.junit (junit-4.12.jar)"; "org.junit.internal.runners" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.internal.runners" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.internal.runners" -> "org.junit.runner.manipulation (junit-4.12.jar)"; "org.junit.internal.runners" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.internal.runners" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.internal.runners.model" -> "java.lang"; "org.junit.internal.runners.model" -> "java.lang.reflect"; "org.junit.internal.runners.model" -> "java.util"; "org.junit.internal.runners.model" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.internal.runners.model" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.internal.runners.model" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.internal.runners.model" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.internal.runners.rules" -> "java.lang"; "org.junit.internal.runners.rules" -> "java.lang.annotation"; "org.junit.internal.runners.rules" -> "java.lang.reflect"; "org.junit.internal.runners.rules" -> "java.util"; "org.junit.internal.runners.rules" -> "org.junit (junit-4.12.jar)"; "org.junit.internal.runners.rules" -> "org.junit.rules (junit-4.12.jar)"; "org.junit.internal.runners.rules" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.internal.runners.statements" -> "java.lang"; "org.junit.internal.runners.statements" -> "java.lang.management"; "org.junit.internal.runners.statements" -> "java.util"; "org.junit.internal.runners.statements" -> "java.util.concurrent"; "org.junit.internal.runners.statements" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.internal.runners.statements" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.matchers" -> "java.lang"; "org.junit.matchers" -> "org.hamcrest (not found)"; "org.junit.matchers" -> "org.hamcrest.core (not found)"; "org.junit.matchers" -> "org.junit.internal.matchers (junit-4.12.jar)"; "org.junit.rules" -> "java.io"; "org.junit.rules" -> "java.lang"; "org.junit.rules" -> "java.lang.management"; "org.junit.rules" -> "java.util"; "org.junit.rules" -> "java.util.concurrent"; "org.junit.rules" -> "org.hamcrest (not found)"; "org.junit.rules" -> "org.junit (junit-4.12.jar)"; "org.junit.rules" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.rules" -> "org.junit.internal.matchers (junit-4.12.jar)"; "org.junit.rules" -> "org.junit.internal.runners.statements (junit-4.12.jar)"; "org.junit.rules" -> "org.junit.matchers (junit-4.12.jar)"; "org.junit.rules" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.rules" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.runner" -> "java.io"; "org.junit.runner" -> "java.lang"; "org.junit.runner" -> "java.lang.annotation"; "org.junit.runner" -> "java.lang.reflect"; "org.junit.runner" -> "java.util"; "org.junit.runner" -> "java.util.concurrent"; "org.junit.runner" -> "java.util.concurrent.atomic"; "org.junit.runner" -> "java.util.regex"; "org.junit.runner" -> "junit.framework (junit-4.12.jar)"; "org.junit.runner" -> "junit.runner (junit-4.12.jar)"; "org.junit.runner" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.runner" -> "org.junit.internal.builders (junit-4.12.jar)"; "org.junit.runner" -> "org.junit.internal.requests (junit-4.12.jar)"; "org.junit.runner" -> "org.junit.internal.runners (junit-4.12.jar)"; "org.junit.runner" -> "org.junit.runner.manipulation (junit-4.12.jar)"; "org.junit.runner" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.runner" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.runner" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.runner.manipulation" -> "java.lang"; "org.junit.runner.manipulation" -> "java.util"; "org.junit.runner.manipulation" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.runner.notification" -> "java.io"; "org.junit.runner.notification" -> "java.lang"; "org.junit.runner.notification" -> "java.lang.annotation"; "org.junit.runner.notification" -> "java.util"; "org.junit.runner.notification" -> "java.util.concurrent"; "org.junit.runner.notification" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.runners" -> "java.lang"; "org.junit.runners" -> "java.lang.annotation"; "org.junit.runners" -> "java.lang.reflect"; "org.junit.runners" -> "java.text"; "org.junit.runners" -> "java.util"; "org.junit.runners" -> "java.util.concurrent"; "org.junit.runners" -> "org.junit (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.internal.builders (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.internal.runners (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.internal.runners.model (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.internal.runners.rules (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.internal.runners.statements (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.rules (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.runner.manipulation (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.runners.parameterized (junit-4.12.jar)"; "org.junit.runners" -> "org.junit.validator (junit-4.12.jar)"; "org.junit.runners.model" -> "java.lang"; "org.junit.runners.model" -> "java.lang.annotation"; "org.junit.runners.model" -> "java.lang.reflect"; "org.junit.runners.model" -> "java.util"; "org.junit.runners.model" -> "java.util.concurrent"; "org.junit.runners.model" -> "org.junit (junit-4.12.jar)"; "org.junit.runners.model" -> "org.junit.internal (junit-4.12.jar)"; "org.junit.runners.model" -> "org.junit.internal.runners (junit-4.12.jar)"; "org.junit.runners.model" -> "org.junit.internal.runners.model (junit-4.12.jar)"; "org.junit.runners.model" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.runners.parameterized" -> "java.lang"; "org.junit.runners.parameterized" -> "java.lang.annotation"; "org.junit.runners.parameterized" -> "java.lang.reflect"; "org.junit.runners.parameterized" -> "java.util"; "org.junit.runners.parameterized" -> "org.junit.runner (junit-4.12.jar)"; "org.junit.runners.parameterized" -> "org.junit.runner.notification (junit-4.12.jar)"; "org.junit.runners.parameterized" -> "org.junit.runners (junit-4.12.jar)"; "org.junit.runners.parameterized" -> "org.junit.runners.model (junit-4.12.jar)"; "org.junit.validator" -> "java.lang"; "org.junit.validator" -> "java.lang.annotation"; "org.junit.validator" -> "java.util"; "org.junit.validator" -> "java.util.concurrent"; "org.junit.validator" -> "org.junit.runners.model (junit-4.12.jar)"; } |
Das wollen wir jetzt noch graphisch darstellen:
1 |
fdp -T png -o junit-4.12.png junit-4.12.jar.dot |
Oder kurz:
1 |
fdp -T png -o summary.png summary.dot |
Das Ergebnis: