Created
January 9, 2024 09:05
-
-
Save JonasGao/0501a40f9645b91984cd6e752bf4413e to your computer and use it in GitHub Desktop.
Manually Release Maven Project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Switch] | |
$GetVersion, | |
$ReleaseVersion, | |
$NextVersion, | |
$Setting | |
) | |
function Start-Maven() | |
{ | |
Write-Host "Run: mvn $args" -ForegroundColor Green | |
if ($Setting) | |
{ | |
mvn -s "$Setting" $args | |
} | |
else | |
{ | |
mvn $args | |
} | |
if (-not($?)) | |
{ | |
throw "Maven failed" | |
} | |
} | |
function Start-Git() | |
{ | |
Write-Host "Run: git $args" -ForegroundColor Green | |
git $args | |
} | |
function Resolve-CurrentVersion() | |
{ | |
$NS = @{ | |
mvn = "http://maven.apache.org/POM/4.0.0" | |
} | |
Select-Xml -Path .\pom.xml -XPath /mvn:project/mvn:version -Namespace $NS ` | |
| Select-Object -ExpandProperty Node ` | |
| Select-Object -ExpandProperty InnerText | |
} | |
function Resolve-ReleaseVersion() | |
{ | |
$V = Resolve-CurrentVersion | |
$V.Replace("-SNAPSHOT", "") | |
} | |
function Resolve-NextVersion() | |
{ | |
$V = Resolve-ReleaseVersion | |
$V = $V.Split(".") | |
$V[2] = [int]$V[2] + 1 | |
$V = $V -join "." | |
$V + "-SNAPSHOT" | |
} | |
if ($GetVersion) | |
{ | |
Resolve-CurrentVersion | |
exit | |
} | |
if (-not($ReleaseVersion)) | |
{ | |
$ReleaseVersion = Resolve-ReleaseVersion | |
} | |
if (-not($NextVersion)) | |
{ | |
$NextVersion = Resolve-NextVersion | |
} | |
Write-Output "Release version: $ReleaseVersion" | |
Write-Output "Next version: $NextVersion" | |
if ($Setting) | |
{ | |
Write-Output "Setting: $Setting" | |
} | |
Start-Maven -B versions:set "-DnewVersion=$ReleaseVersion" | |
Start-Git commit -a -m "Release $ReleaseVersion" | |
Start-Git tag "$ReleaseVersion" | |
Start-Maven clean package -P production | |
Start-Maven -B versions:set "-DnewVersion=$NextVersion" | |
Start-Git commit -a -m "Update next version" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment