Viewing Module Dependencies – Java Module System

Viewing Module Dependencies

If the default output from the jdeps command is overwhelming, it can be filtered. The -summary option (short form: -s) will only print the module dependencies, as shown by the jdeps command below. Only the module dependencies of the main module will be shown in the output.

Click here to view code image

>
jdeps –module-path mlib –module main -summary

main -> controller
main -> java.base

If we use the –recursive option (short form: -R) with the -summary option (short form: -s), then the module dependencies of each module will be printed recursively, starting with the specified module.

Click here to view code image

>
jdeps –module-path mlib –module main -summary –recursive              (1)

controller -> java.base
controller -> model
controller -> view
main -> controller
main -> java.base
model -> java.base
view -> java.base
view -> model

Finally, we illustrate the graph-generating capabilities of the jdeps tool. The jdeps command takes all JARs of the adviceApp application from the mlib directory and creates a module graph (options -summary and –recursive) in the DOT format (option -dotoutput) under the current directory. The DOT file summary.dot containing the graph will be created. Using the dot command, this graph can be converted to a pdf file (summary.pdf) as shown in Figure 19.18.

Figure 19.18 Module Graph Using the jdeps Tool

Click here to view code image

>
jdeps -dotoutput . -summary –recursive  mlib/*
>
dot -Tpdf summary.dot >summary.pdf

The module graph in Figure 19.18 shows the same module dependencies printed by the jdeps command above at (1). Comparing the module graph in Figure 19.18 with the one in Figure 19.8, we see that jdeps has added the implicit dependency of each module on the java.base module.

Viewing Class-Level Dependencies

It is possible to dive deeper into dependencies with the jdeps tool. The -verbose option (short form: -v) will elicit the class dependencies of the specified module. Instead of package dependencies to round off the output, class dependencies are listed. The last line in the output shows that the class com.passion.main.Main in the main module depends on the java.lang.String class in the java.base module.

Click here to view code image

>
jdeps –module-path mlib –module main -verbose
main
 [file:…/adviceApp/mlib/main.jar]
   requires controller
   requires mandated java.base (@17.0.2)
main -> controller
main -> java.base
   com.passion.main.Main  -> com.passion.controller.AdviceController  controller
   com.passion.main.Main  -> java.lang.Object                         java.base
   com.passion.main.Main  -> java.lang.String                         java.base

If we use the –recursive option (short form: -R) with the -verbose option (short form: -v), then the class dependencies of each module will be printed recursively, starting with the specified module.

Click here to view code image

>
jdeps –module-path mlib –module main -verbose –recursive

controller

main

model

view


Leave a Reply

Your email address will not be published. Required fields are marked *