25 lines
1.3 KiB
PowerShell
25 lines
1.3 KiB
PowerShell
$ErrorActionPreference='Stop'
|
|
$candidates=New-Object 'System.Collections.Generic.List[string]'
|
|
foreach($base in @('C:\Program Files','D:\Program Files','D:\ProgramFiles')) {
|
|
foreach($folder in @(Get-ChildItem -LiteralPath $base -Directory -ErrorAction SilentlyContinue | Where-Object {$_.Name -match 'Java|JDK|Android|Studio|JetBrains|Microsoft|Eclipse|BellSoft'})) {
|
|
$candidates.Add($folder.FullName)
|
|
$candidates.Add((Join-Path $folder.FullName 'jbr'))
|
|
foreach($child in @(Get-ChildItem -LiteralPath $folder.FullName -Directory -ErrorAction SilentlyContinue)) {
|
|
$candidates.Add($child.FullName)
|
|
$candidates.Add((Join-Path $child.FullName 'jbr'))
|
|
}
|
|
}
|
|
}
|
|
$selected=$null
|
|
foreach($candidate in $candidates) {
|
|
$release=Join-Path $candidate 'release'
|
|
if((Test-Path -LiteralPath "$candidate\bin\java.exe") -and (Test-Path -LiteralPath $release)) {
|
|
$version=Get-Content -LiteralPath $release | Where-Object {$_ -match '^JAVA_VERSION="(17|21)\.'}
|
|
if($version){$selected=$candidate;break}
|
|
}
|
|
}
|
|
if(-not $selected){$selected='C:\Program Files\Java\jdk-25.0.3';Write-Output 'Only JDK25 detected; older Gradle projects require configuring a compatible JDK.'}
|
|
Write-Output "Selected JAVA_HOME=$selected"
|
|
& "$PSScriptRoot\install.ps1" -JavaHome $selected
|
|
& "$PSScriptRoot\verify.ps1"
|