$ErrorActionPreference = 'Stop' $Root = Split-Path $PSScriptRoot -Parent $Jar = Join-Path $Root 'gradle/wrapper/gradle-wrapper.jar' $Work = Join-Path (Split-Path $Jar) "bootstrap.$([guid]::NewGuid().ToString('N'))" $Temp = Join-Path $Work 'wrapper.jar' $Expected = '7d3a4ac4de1c32b59bc6a4eb8ecb8e612ccd0cf1ae1e99f66902da64df296172' $DistExpected = '6f74b601422d6d6fc4e1f9a1ab6522f642c2fdcbc15ae33ebd30ba3d7198e854' New-Item -ItemType Directory -Force -Path $Work | Out-Null try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Invoke-WebRequest -UseBasicParsing -Uri 'https://raw.githubusercontent.com/gradle/gradle/v8.14.5/gradle/wrapper/gradle-wrapper.jar' -OutFile $Temp $Actual = (Get-FileHash -Algorithm SHA256 $Temp).Hash.ToLowerInvariant() if ($Actual -ne $Expected) { Write-Host 'Tag wrapper differs from release; retrieving the verified release distribution.' $Dist = Join-Path $Work 'gradle.zip' Invoke-WebRequest -UseBasicParsing -Uri 'https://services.gradle.org/distributions/gradle-8.14.5-bin.zip' -OutFile $Dist if ((Get-FileHash -Algorithm SHA256 $Dist).Hash.ToLowerInvariant() -ne $DistExpected) { throw 'Distribution checksum mismatch; refusing to execute.' } Add-Type -AssemblyName System.IO.Compression.FileSystem $Outer = [IO.Compression.ZipFile]::OpenRead($Dist) try { $Entries = @($Outer.Entries | Where-Object { $_.FullName -match '/gradle-wrapper-main-8\.14\.5\.jar$' }) if ($Entries.Count -ne 1) { throw 'Expected exactly one wrapper-main JAR.' } $Main = Join-Path $Work 'wrapper-main.jar' [IO.Compression.ZipFileExtensions]::ExtractToFile($Entries[0], $Main, $true) } finally { $Outer.Dispose() } $Inner = [IO.Compression.ZipFile]::OpenRead($Main) try { $Entry = $Inner.GetEntry('gradle-wrapper.jar') if ($null -eq $Entry) { throw 'Embedded wrapper missing.' } [IO.Compression.ZipFileExtensions]::ExtractToFile($Entry, $Temp, $true) } finally { $Inner.Dispose() } if ((Get-FileHash -Algorithm SHA256 $Temp).Hash.ToLowerInvariant() -ne $Expected) { throw 'Embedded wrapper checksum mismatch; refusing to execute.' } } Move-Item -Force $Temp $Jar Write-Host 'Official Gradle 8.14.5 wrapper verified.' } finally { if (Test-Path $Work) { Remove-Item -Recurse -Force $Work } }