Script to view a jars transitive dependencies

by 5/08/2017 12:26:00 PM 0 comments
Very often when I'm programming in Java, I need to see the dependencies for a particular jar file. If you are working in a project using a build tool like Maven or SBT, it's quite trivial to dump out a dependency tree of all the jars in the project. Outside of the project it's a pain, generally you have to throw together a quick project and then run your tool on it. As a workaround, I threw together a script that does that for you (and cleans up afterwards) Just copy the code into a file named `mvntree`. You should tweak the included repositories to reflect ones that you may need. To run it use:

mvntree groupId artifactId version

For example:

mvntree edu.ucar netcdf4 4.6.9


#!/usr/bin/env bash

# Usage: mvntree groupId artifactId version


mkdir -p "$MY_DIR" && \
  cat > "$MY_DIR/pom.xml" <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
   <name>Maven Quick Start Archetype</name>
<!-- add here other dependencies -->

cd "$MY_DIR" && \
mvn -e dependency:tree -U

cd "$CUR_DIR"
rm -rf $MY_DIR 

Brian Schlining


Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.