DEV Community

mafflerbach
mafflerbach

Posted on

1

Java dependency viewer with maven and fzf

Sometimes it is necessary to take a look in the dependencies and there classes and methods. Every good IDE has this on board, and you can easily scroll and search for the libs and the classes. But sometimes you may want to take a fast look and don't want to boot your favourite IDE, or you like to self-mortification and you are using Vim.

As coc-vim does a good job to bring the language server support to Vim some of the convenience are sometimes missing. One of this is the mentioned dependency overview. For this case, I wrote a small script:

#!/bin/bash

# generate dependency list if not exists
if [ ! -f .dependencies ]; then
    echo "Generate dependency list"
    mvn dependency:list -DoutputFile=./.dependencies
fi

# check the last modified, if pom is younger the dependency list will be updated
if [ .dependencies -ot pom.xml  ]
then
    mvn dependency:list -DoutputFile=./.dependencies
fi
# open selection list for the dependencies
dependencies=$(cat ./.dependencies|fzf)

packagePath=$(echo $dependencies | cut -d':' -f1 | sed -e 's/\./\//g')
packageName=$(echo $dependencies | cut -d':' -f2)
version=$(echo $dependencies | cut -d':' -f4)

path=$packagePath/$packageName/$version
jar=$packageName-$version.jar

# open selection list for the containing class of the package
classFile=$(jar tf /home/maren/.m2/repository/$path/$jar | grep class | fzf )

# shows the public methods of the classes.
output=$(javap  jar:file:///home/maren/.m2/repository/$path/$jar!/$classFile)
# like cat but on steroids. 
bat --line-range 2:9999 -l Java <<<  $output

Enter fullscreen mode Exit fullscreen mode

Here is a small demo:

Dependencie viewer

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more