Created
October 24, 2024 14:19
-
-
Save maksimr/2b450329d868b99e65b0ec37aa651c12 to your computer and use it in GitHub Desktop.
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
<# | |
.SYNOPSIS | |
# Runs Gradle Wrapper from any project's subdirectory | |
#> | |
function gradlew { | |
$Local:currentDir = Get-Location | |
$Local:gradlew = $null | |
$Local:dirStack = @() | |
while ($null -ne $currentDir) { | |
$dirStack += $currentDir | |
$gradlew = Get-ChildItem -Path $currentDir -Filter "gradlew.bat" | Select-Object -First 1 | |
if ($null -ne $gradlew) { | |
# Exit if we find gradlew.bat | |
break | |
} | |
if ($HOME -eq $currentDir) { | |
# Exit if we reach the Home directory | |
break | |
} | |
if (Test-Path -Path (Join-Path -Path $currentDir -ChildPath ".git")) { | |
# Exit if we reach project root directory | |
break | |
} | |
$currentDir = Get-Item -Path $currentDir | Select-Object -ExpandProperty Parent | |
} | |
if ($null -eq $gradlew) { | |
$Local:trace = $dirStack.ForEach({ "`n$_" }) -join '' | |
Write-Error "Cannot find 'gradlew.bat' $trace" | |
return | |
} | |
$Local:procArgs = $args | |
$procArgs += "-p" | |
$procArgs += $currentDir | |
Start-Process ` | |
-NoNewWindow ` | |
-Wait ` | |
-FilePath $gradlew ` | |
-ArgumentList $procArgs ` | |
-WorkingDirectory $currentDir | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment