因为mvn dependency:tree 包含了很多其他杂乱的信息,就写个简单的小脚本查看关系依赖树的关键部分!
#!/bin/bash
# show part of mvn dependency:tree result
# author :zhaoming.xue
# data :2012-4-18
# last modify :2012-4-18
# version :1.0.0
# 1.check has the pom.xml file
pom_file_num=`find . -maxdepth 1 -type f | grep pom.xml | wc -l`
if [ $pom_file_num -eq 0 ];then
echo "can't find pom.xml ,pls check ! "
exit 1
fi
base_path=`pwd`
# 2.cut part of info
# 2.1 execute and check has error !
mvn dependency:tree > temp.info
if [ -f temp.info ];then
has_error=`grep -i "error" temp.info | wc -l`
if [ $has_error -gt 0 ];then
echo "error ,pls check temp.info"
exit 1
fi
fi
# 2.2 cut info
start_num=`grep -n + temp.info | awk -F ":" '{print $1}' | sed '2,$d'`
new_start_num=`expr $start_num - 1`
end_num=`grep -in "build success" temp.info | awk -F ":" '{print $1}'`
if [ $? -gt 0 ];then
echo "error ,pls check "
exit 1
fi
sed -n "$new_start_num,$end_num p" temp.info
# 3.delete temp file
if [ -f temp.info ];then
rm -rf temp.info
fi
本文介绍了一个用于简化Maven依赖树展示的bash脚本,该脚本可以帮助开发者更清晰地查看项目的依赖关系,避免无关信息干扰。通过执行特定命令并筛选关键输出,能够有效地定位到项目的直接依赖及传递性依赖。

811

被折叠的 条评论
为什么被折叠?



