Skip to content

Instantly share code, notes, and snippets.

@kostapc
Last active November 10, 2023 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostapc/3912562751e3aaf05d5bdbb337b5431c to your computer and use it in GitHub Desktop.
Save kostapc/3912562751e3aaf05d5bdbb337b5431c to your computer and use it in GitHub Desktop.
powershell gradle short alias
### https://gist.github.com/kostapc/3912562751e3aaf05d5bdbb337b5431c
#
# gw fast - just build. Skip tests and checkstyle
# gw tree :path:to:project file.txt - print dependencies tree to file
# gw local - install to local maven repository
#
# After script downloading you should unblock it: Unblock-File -Path 'C:\%PATH_TO_SCRIPT%\gw.ps1'
#
$path = ".\gradlew.bat"
$configFile = "$HOME\.gradle\gw.json"
$out_file = ""
[Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("utf-8")
if($args[0] -eq "repack") {
Write-Host "clear and build artifacts" -ForegroundColor DarkRed
&$path @('clean')
&$path @('assemble')
Exit
}
if($Args[0] -eq "fast") {
$skipAllArgs = "-x test -x checkstyleMain -x checkstyleTest -x spotbugsMain -x spotbugsTest" # -x checkCoverage"
Write-Host "no tests, not checkstyle, no pain" -ForegroundColor DarkRed
$args = "build $skipAllArgs".Split(" ")
}
if($Args[0] -eq "tree") {
# gw :path:to:project > deps_def.txt
$module = $args[1]
$out_file = $module+"-tree.txt"
Write-Host "writing dependency tree to file $out_file" -ForegroundColor DarkRed
$args = $module+":dependencies".Split(" ")
}
if($Args[0] -eq "local") {
Write-Host "publishing to local maven repository" -ForegroundColor DarkRed
$args = "publishToMavenLocal $skipAllArgs".Split(" ")
}
[Collections.Generic.List[String]]$listArgs = $args
if (Test-Path $path) {
$cache_host = ""
if (Test-Path $configFile)
{
$config = Get-Content -Raw -Path $configFile | ConvertFrom-Json
$cache_host = $config."caching-host"
$ping_result = (test-connection -computername $cache_host -quiet)
if (!$ping_result)
{
Write-Host "cache host '$cache_host' is down, cache disabled" -ForegroundColor Red
}
}
if($cache_host -ne "" -and $ping_result) {
#$listArgs.Add("-Dorg.gradle.caching.debug=true")
$Env:GRADLE_CACHE_HOST=$cache_host
Write-Host "caching on $Env:GRADLE_CACHE_HOST" -ForegroundColor Magenta
}
$listArgs.Add("--build-cache") # cache enabled everytime
Write-Host "actual args: $listArgs" -ForegroundColor Magenta
if($out_file.Length -gt 0) {
&$path $listArgs | Out-File -Encoding utf8 $out_file
} else {
&$path $listArgs
}
} else {
Write-Host "there is no gradle in this directory" -ForegroundColor Magenta
}
#
# config sample
# locate at $HOME\.gradle\gw.json
# {
# "caching-host":"http://gradle-cahce-host/"
# }
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment