Skip to content

Instantly share code, notes, and snippets.

@kevin-lee
Last active December 11, 2015 05:48
Show Gist options
  • Save kevin-lee/4554497 to your computer and use it in GitHub Desktop.
Save kevin-lee/4554497 to your computer and use it in GitHub Desktop.
Simple script to get a maven dependency tree without using maven's options which are hard to remember.
#!/bin/bash
##########################################################
## Simple script to get maven dependency tree ##
## @author Lee, SeongHyun (Kevin) ##
## @veraion 0.0.1 (2013-01-17) ##
## ##
## To change the option 'include' and 'output', change ##
## the values of INCLUDE_NAME and OUTPUT_NAME ##
## respectively. ##
## e.g.) to change 'include' to 'inc' and 'output' to ##
## 'out', ##
## INCLUDE_NAME="inc" ##
## OUTPUT_NAME="out" ##
##########################################################
extra_options=""
TMP_IFS=$IFS
IFS="="
INCLUDE_NAME="include"
OUTPUT_NAME="output"
if [ -n "$1" ]
then
array1=( $1 )
if [ "${array1[0]}" == $INCLUDE_NAME ]
then
extra_options="-Dincludes=${array1[1]}"
elif [ "${array1[0]}" == $OUTPUT_NAME ]
then
extra_options="-DoutputFile=${array1[1]}"
fi
fi
if [ -n "$2" ]
then
array2=( $2 )
if [ "${array2[0]}" == $INCLUDE_NAME ]
then
extra_options="$extra_options -Dincludes=${array2[1]}"
elif [ "${array2[0]}" == $OUTPUT_NAME ]
then
extra_options="$extra_options -DoutputFile=${array2[1]}"
fi
fi
IFS=$TMP_IFS
echo -e "execute \"mvn dependency:tree $extra_options\"\n"
mvn dependency:tree $extra_options
exit
@kevin-lee
Copy link
Author

Add the following alias to your ~/.bashrc.

alias dep-tree='~/mvn-dep-tree.sh' 

Then you can run it like

$ dep-tree 

If you want to specify "-Dincludes" option, do this.

$ dep-tree include=something 

"-DoutputFile" can also be specified.

$ dep-tree output=~/Desktop/output.txt 

Or both can be

$ dep-tree include=something output=~/Desktop/output.txt 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment