gradle#
A thin, predictable wrapper around the Gradle wrapper.
Kept separate from the android module on purpose: Gradle is also used for plain
JVM host components that have no Android SDK and no APK, and those callers should
not have to import an Android toolchain to run test.
Every function prefers the project's own ./gradlew over a system gradle,
because the wrapper pins the Gradle version and a system gradle does not.
Functions#
gradle_available [dir=.]- Purpose: Report whether
dircan be built - a Gradle wrapper is present, or a systemgradleis onPATH. -
Returns: 0 when Gradle is reachable; non-zero otherwise.
-
gradle_wrapper [dir=.] - Purpose: Print the Gradle command to use for
dir. -
Returns: 0 and the absolute path to
dir/gradlew, or the literalgradle; 3 when neither is available. -
gradle_run <dir> <task...> - Purpose: Run Gradle tasks in
dir. Adds--no-daemon, because a daemon left running between local checks is a surprise memory cost on a laptop. - Args:
dir- existing project directory.task...- one or more Gradle task names.
- Returns: 2 for missing arguments or a non-existent directory; 3 when no Gradle is available; otherwise Gradle's own exit status.
-
Example:
gradle_run android testDebugUnitTest -
gradle_lint [dir=.] -
Purpose: Run the
linttask. -
gradle_test [dir=.] -
Purpose: Run the
testtask. -
gradle_assemble [dir=.] [variant=Debug] - Purpose: Run
assemble<Variant>. The first letter of the variant is capitalized as Gradle expects it, soreleaserunsassembleRelease; the rest is passed through (prodReleaserunsassembleProdRelease). -
Example:
gradle_assemble android Release -
gradle_clean [dir=.] - Purpose: Run the
cleantask.
Environment#
No environment variables are required.
Dependencies#
A project Gradle wrapper, or gradle on PATH. A JDK, as Gradle requires.
PowerShell#
ps/lib/gradle.ps1 mirrors this module with the same function names. On Windows
the wrapper is gradlew.bat, and presence is tested with Test-Path rather than
an executable bit, which NTFS does not have.