How to run Gradle from the command line on Mac bash
For a quick start, use the command ./gradlew build in the root directory of a project that uses the Gradle Wrapper. Remember to give gradlew permission to execute via chmod +x gradlew. For those using a direct Gradle installation, gradle build should do the trick, provided gradle is in your PATH.
Ensure your CLI is at your rooting (pun intended) for your project's root, where the build.gradle file is. Move there with cd /path/to/project if needed.
Verifying project setup
Before showing off your Gradle command skills, check your project setup:
-
gradlewshould be partying in your project root. Check that! -
Visit
ls -l gradlewto check ifgradlewhas its party hat on aka thexpermission. If missing, gift it withchmod +x gradlew. -
Add the path to
gradlewto yourPATHfor handy access: -
Run
gradle -vto check Gradle's ID and confirm it indeed is who it claims.
When Gradle grumbles: Troubleshooting
Run into issues? Fret not, here're your Gradle Issue Goggles:
- Seeing a "gradlew not found"? Confirm your directory or
PATHhasgradlewinvited. - File permissions often play spoilsport. Ensure
gradlewhas its party hat (xpermission) withchmod +x gradlew. - If issues still party on, your project's documentation or community forums might be the party pooper.
- To check for freebies (tests), run:
- Tinkering with Android Studio or an Android project? Navigate to the party spot usually named
android.
Customizing Gradle runs
Like how you prefer your coffee, here's how to tweak your Gradle commands to your liking:
- Append
--scanto your commands for a detailed brewing report. - Unveil all tasks prepared for the party with
gradle tasks. - Bump into nasty environment variables or aliases? Check your shell's guest list (
/.bashrcor/.bash_profile).
Gradle via Homebrew
If you prefer your Gradle installation straight-up (via Homebrew), do:
- Install Gradle with:
brew install gradle # Brew a pot of Gradle
- Post Homebrew installation, you can run Gradle commands **globally**. Handy right?
Was this article helpful?