#!/bin/bash
source_file=/opt/report.txt
target_file=/opt/comma_report.txt
#Clean source file from "[INFO]"
sed 's/\[INFO\] //g' $source_file > /tmp/clean_report.txt
#Join next line to the previous one if it starts with more than 3 spaces
sed -i -E ':a ; $!N ; s/\n^ / / ; ta ; P ; D' /tmp/clean_report.txt
#Clean file from more than 2 spaces
sed -i 's/ *//g' /tmp/clean_report.txt
#Grep for arrows, sort and send result to grepped_report.txt
grep "\->" /tmp/clean_report.txt | awk '!x[$0]++' > /tmp/grepped_report.txt
#Clean file from ".RELEASE"
sed -i 's/.RELEASE//g' /tmp/grepped_report.txt
#Replace arrows with commas
sed -i 's/->/,/g' /tmp/grepped_report.txt
#Replace more than 2 dots with comma and send the output to target file
sed -r -e 's/\.{3,}/,/g' /tmp/grepped_report.txt > $target_file
#Delete tmp files
rm /tmp/clean_report.txt
rm /tmp/grepped_report.txt
#The end
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# run maven to generate dependency report
./mvnw versions:dependency-updates-report
# use default report location
REPORT="target/dependency-updates-report.xml"
# get the number of dependencies using the latest version
NEXT_VERSION_AVAILABLE=$(cat ${REPORT} | dasel --read xml ".DependencyUpdatesReport.summary.nextVersionAvailable")
NEXT_INCREMENTAL_AVAILABLE=$(cat ${REPORT} | dasel --read xml ".DependencyUpdatesReport.summary.nextIncremetalAvailable")
NEXT_MINOR_AVAILABLE=$(cat ${REPORT} | dasel --read xml ".DependencyUpdatesReport.summary.nextMinorAvailable")
NEXT_MAJOR_AVAILABLE=$(cat ${REPORT} | dasel --read xml ".DependencyUpdatesReport.summary.nextMajorAvailable")
# compare number of outdated dependencies with our threshold
if [ "${NEXT_VERSION_AVAILABLE}" -ne 0 ]; then
echo "Error: ${NEXT_VERSION_AVAILABLE} next versions are available"
exit 1
elif [ "${NEXT_INCREMENTAL_AVAILABLE}" -ne 0 ]; then
echo "Error: ${NEXT_INCREMENTAL_AVAILABLE} next incremental versions are available"
exit 1
elif [ "${NEXT_MINOR_AVAILABLE}" -ne 0 ]; then
echo "Error: ${NEXT_MINOR_AVAILABLE} next minor versions are available"
exit 1
elif [ "${NEXT_MAJOR_AVAILABLE}" -ne 0 ]; then
echo "Error: ${NEXT_MAJOR_AVAILABLE} next major versions are available"
exit 1
fi
3条答案
按热度按时间kzipqqlq1#
因此,没有任何担保,这里有一段bash脚本,这要感谢我的一个同事,它从display-plugin-updates中获取输出|display-dependency-更新并转换为逗号分隔的列表;支持多行输出,为我们工作
5ktev3wc2#
我有同样的问题,现在有一个简单的解决办法。
首先,您必须使用
versions:dependency-updates-report
而不是versions:display-dependency-updates
。默认情况下,它在
target/site/dependency-updates-report.html
中生成一个HTML文件。更改pom.xml
中的配置以获得XML格式的结果。现在再次运行目标,您应该在
target/dependency-updates-report.xml
处看到XML文件。我在CI/CD管道中使用dasel来处理这个文件。当我有一个过时的依赖项时,管道就会中断。
我希望这对您和任何在线搜索后可能访问这里的人有所帮助。让我们确保在Maven项目中没有使用过时的依赖项。
eqqqjvef3#
我正在使用下面的命令来列出一个项目的依赖关系在CSV格式对一个pom文件,你可以调整命令与
versions:display-plugin-updates
根据您的需要--U
=强制检查来自远程的更新versions:display-dependency-updates
=列出所有依存关系更新-Dversions.outputLineWidth=120
=所需版本插件版本〉2.10.0-DprocessDependencyManagement=false
和-DprocessPluginDependenciesInPluginManagement=false
=从列表中排除while部分逐行打印输出