param([Parameter(ValueFromRemainingArguments = $true)][string[]]$MavenArguments = @('verify')) $ErrorActionPreference = 'Stop' $mavenCommand = Get-Command mvn.cmd -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 if ($mavenCommand) { $mavenExecutable = $mavenCommand.Source } else { $ideaMaven = Join-Path $env:LOCALAPPDATA 'Programs/IntelliJ IDEA/plugins/maven-plugin/lib/maven3/bin/mvn.cmd' if (-not (Test-Path -LiteralPath $ideaMaven)) { throw '請將 Maven 加入 PATH,或使用 IntelliJ IDEA 的 Maven 面板執行 verify。' } $mavenExecutable = $ideaMaven } Push-Location $PSScriptRoot try { & $mavenExecutable @MavenArguments if ($LASTEXITCODE -ne 0) { throw "Maven 建置失敗(exit=$LASTEXITCODE)。" } } finally { Pop-Location }