Can jdeps resolve unnecessary dependencies?
jwkozaczuk at gmail.com
Wed Sep 7 14:12:56 UTC 2016
Thanks for you response.
Will I be able to take advantage of jlink's ability to produce subset-only
image of the JRE even if I do not use new Java 9 modular jars? In other
words if my app.jar and other dependent jars are old java 8 ones and do not
have any module descriptors will jlink be able to identify only needed JRE
modules and produce minimal runtime image?
On Tue, Sep 6, 2016 at 10:24 PM, Mandy Chung <mandy.chung at oracle.com> wrote:
> > On Sep 6, 2016, at 6:07 PM, Waldek Kozaczuk <jwkozaczuk at gmail.com>
> > 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
> $ 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
>  and JEP 282 
>  http://openjdk.java.net/jeps/261
>  http://openjdk.java.net/jeps/282
More information about the jigsaw-dev