How to automate build in gradle?

Whenever I edit something in the build.gradle file I need to sync it, but this is available only in the ide s to sync but I don’t want to install android studio or anything in Linux (cause : GUI is not installed in it)
How can I sync Gradle in the terminal
gradlew sync
does not work it shows errors but if the same project is synced on my windows machines the gradle commands start working.

Longstory short I want a way to sync gradle in terminal itself.

For solution please refer to this link: How to automate build in gradle? - Help/Discuss - Gradle Forums