$ErrorActionPreference = "Stop"

$projectRoot = Split-Path -Parent $PSScriptRoot
$applicationDir = Join-Path $projectRoot "application"
$gradleWrapper = Join-Path $applicationDir "gradlew.bat"
$projectCache = Join-Path $projectRoot ".gradle-project-cache"
$env:GRADLE_USER_HOME = Join-Path $projectRoot ".gradle-user"

if (-not $env:JAVA_HOME) {
    throw "JAVA_HOME ist nicht gesetzt. Bitte Microsoft OpenJDK 25 konfigurieren."
}

& $gradleWrapper -p $applicationDir --project-cache-dir $projectCache :desktopApp:run
exit $LASTEXITCODE
