Use case
The downloaded snapshot has timestamp associated with it like the following:
artifact-1.0.0-20211012.041152-1.jar
But the tooling is expecting an absolute name like the the following:
artifact-1.0.0-SNAPSHOT.jar
Powershell Script
#The target artifact
$ArtifactId = "artifact"
#The target SNAPSHOT version
$Version = "1.0.0-SNAPSHOT"
if ($Version -match "^(.*)-SNAPSHOT$")
{
$Prefix = "{0}-{1}" -f $ArtifactId,$Matches.1
$Pattern = "^(${Prefix}).*(\.jar)$"
Get-ChildItem ('.') | ForEach-Object {
If ($_.Name -match $Pattern) {
$NewName = "{0}-SNAPSHOT{1}" -f $Matches.1, $Matches.2
Rename-Item $_ -NewName $NewName
$Message = "Renaming from {0} to {1}" -f $_.Name, $NewName
echo $Message
}
}
}
Leave a Reply