如果groupid匹配,则更新所有arctifactivid的版本



我有一个pom.xml文件,如下所示,我需要更新groupId为"org.springframework;并且版本低于"0";2.3.18";

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.3.15</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>2.3.15</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>2.3.15</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.2</version>
</dependency>

如果groupid是",我需要更新所有artifactId版本的版本;org.springframework;

我正在字符串的代码

sed -i '/<artifactId>org.springframework<\/artifactId>/{n;s/<version>.*<\/version>/<version>/<version>5.3.18<\/version>/}' pom.xml

更改后预期的pom文件

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>2.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>2.3.18</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.2</version>
</dependency>

您可以使用maven-versions-plugin中的use dep版本mojo为您完成任务:

mvn versions:use-dep-version -Dincludes="org.springframework:*" -DdepVersion=<new version>

如果可能的话,考虑将property用于spring版本,这样您只需要在一个地方更改版本,例如:

<properties>
<spring.version>2.3.15</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>

或弹簧BOM,定义弹簧工件的所有版本:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>2.3.15</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<!-- no version tag needed here, the correct version from BOM is used -->
</dependency>
</dependencies>
myVersion="2.3.18"
POM=pom.xml
while read nr
do
nr=$((nr+2))
version=$(sed -n ''$nr''p $POM|awk -F"[><]" '{print $3}')
[ "$version" = "$myVersion" ] && continue
sortedVersion=$(echo "$version $myVersion"|tr ' ' 'n'|sort -V|tail -1)
if [ "$sortedVersion" = "$myVersion" ]
then
echo update line $nr. from  $version to $myVersion
sed -i ''$nr's/(<version>)(.*)(</version>)/1'$myVersion'3/' $POM
fi
done < <(grep -n "<groupId>org.springframework" $POM|awk -F: '{print $1}')

update line 4. from 2.3.15 to 2.3.18
update line 9. from 2.3.15 to 2.3.18
update line 14. from 2.3.15 to 2.3.18

相关内容

  • 没有找到相关文章

最新更新