Can jdeps resolve unnecessary dependencies?

Mandy Chung mandy.chung at
Wed Sep 7 02:24:56 UTC 2016

> On Sep 6, 2016, at 6:07 PM, Waldek Kozaczuk <jwkozaczuk at> wrote:
> So jdeps can recursively identify all dependencies given a list of the
> jars that my application is made of. Assume my main application jar is
> app.jar and it depends (per gradle or maven dependencies resolution) on
> following libraries like so:
> app.jar ----> a.jar, b.jar
> a.jar --> x.jar, y.jar, z.jar
> x.jar -> profile1
> y.jar -> profile2
> z.jar -> profile3
> And now assume that the app.jar in reality depends only on the part of
> a.jar that depends only on x.jar. In other words in reality statically
> (no reflection) my application does not really depend on y.jar and z.jar
> and only needs compact1 to execute properly. There are libraries that
> are "well focused" and have very few dependencies and there are those
> that pull ton of dependencies even though an application may only be
> using 5% of it.
> Would jdeps show only real or all dependencies in this case? If latter
> would it show enough information that can be analyzed to determine that
> y.jar and z.jar are not really needed and can be removed from my deployment?

$ jdeps -R -s -cp a.jar:b.jar:x.jar:y.jar:z.jar app.jar

This will recursively analyze the run-time view of the dependencies from app.jar.  The -s option shows the summary and doesn’t list the package-level dependencies.  It will start with all types in app.jar and then transitively analyze the referenced classes.

y.jar and z.jar will not be shown in the output if no type from those jar files are used at runtime.

$ jdeps —-compile-time -s -cp a.jar:b.jar:x.jar:y.jar:z.jar app.jar

This will recursively analyze the compile-time view from app.jar.  It will start with app.jar and then recursively analyze the JAR files containing its referenced types.  In other words, it will show the dependenencies as the example above.

> Would Java 9 jdeps work differently in this case?

jdeps -—compile-time option is a new option added in jdk9 jdeps.

> Would jlink be able to
> figure the "real" dependencies and only pull really needed JRE modules
> into the output image?

jlink will do the resolution per the specified root set and determine the resulting modules to be linked in to the output image.  The dependences are declared in the module descriptors.  You can refer the details in JEP 261 [1] and JEP 282 [2]


More information about the jigsaw-dev mailing list