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
|
[](https://github.com/tcurdt/jdependency/actions)
[](https://codecov.io/gh/tcurdt/jdependency)
[](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.vafer%22%20AND%20a%3A%22jdependency%22)
[](https://gitter.im/tcurdt/jdependency?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
# jdependency - explore your classpath
jdependency is small library that helps you analyze class level dependencies,
clashes and missing classes.
Check the documentation on how to use it with [javadocs](https://tcurdt.github.io/jdependency/apidocs/) and a source
[xref](http://tcurdt.github.io/jdependency/xref/) is also available.
## Where to get it
The jars are available on [maven central](https://repo1.maven.org/maven2/org/vafer/jdependency/).
The source releases you can get in the [download section](https://github.com/tcurdt/jdependency/downloads).
If feel adventures or want to help out feel free to get the latest code
[via git](https://github.com/tcurdt/jdependency/tree/master).
git clone git://github.com/tcurdt/jdependency.git
## How to use it
final File jar1 = ...
final File jar2 = ...
or
final Path jar1 = ...
final Path jar2 = ...
### finding classpath clashes
final Clazzpath cp = new Clazzpath();
cp.addClazzpathUnit(jar1, "jar1.jar");
cp.addClazzpathUnit(jar2, "jar2.jar");
final Set<Clazz> clashed = cp.getClashedClazzes();
for(Clazz clazz : clashed) {
System.out.println("class " + clazz + " is contained in " + clazz.getClasspathUnits());
}
### finding different class versions
final Clazzpath cp = new Clazzpath(true);
cp.addClazzpathUnit(jar1, "jar1.jar");
cp.addClazzpathUnit(jar2, "jar2.jar");
final Set<Clazz> clashed = cp.getClashedClazzes();
final Set<Clazz> uniq = clashed.stream()
.filter(c -> c.getVersions().size() == 1)
.collect(Collectors.toSet());
clashed.removeAll(uniq);
for(Clazz clazz : clashed) {
System.out.println("class " + clazz + " differs accross " + clazz.getClasspathUnits());
}
### finding missing classes
final Clazzpath cp = new Clazzpath();
cp.addClazzpathUnit(jar1, "jar1.jar");
final Set<Clazz> missing = cp.getMissingClazzes();
for(Clazz clazz : missing) {
System.out.println("class " + clazz + " is missing");
}
### finding unused classes
final Clazzpath cp = new Clazzpath();
final ClazzpathUnit artifact = cp.addClazzpathUnit(jar1, "artifact.jar");
cp.addClazzpathUnit(jar2, "dependency.jar");
final Set<Clazz> removable = cp.getClazzes();
removable.removeAll(artifact.getClazzes());
removable.removeAll(artifact.getTransitiveDependencies());
for(Clazz clazz : removable) {
System.out.println("class " + clazz + " is not required");
}
## Related projects
provides a report of the dependencies used/unused and provides a debloated version of the pom.xml
| Project | Description |
|---|---|
| [maven-shade-plugin](https://maven.apache.org/plugins/maven-shade-plugin/) | allows to inline and optimize dependencies into a single jar |
| [gradle-lean](https://github.com/cuzfrog/gradle-lean) | gradle version of the maven-shade plugin (stale) |
| [shadow](https://github.com/johnrengelman/shadow) | gradle version of the maven-shade plugin |
| [jarjar](http://code.google.com/p/jarjar/) | allows to inline and optimize dependencies into a single jar (stale) |
| [proguard](https://github.com/Guardsquare/proguard) | obfuscator, shrinker (GPL) |
| [DepClean](https://github.com/castor-software/depclean) | provides a report of the dependencies used/unused and provides a debloated version of the pom.xml|
## License
All code and data is released under the Apache License 2.0.
|