Your problem is that your println instructions are executed when Gradle parses the build.gradle file, and not when it does the task.
You should move your println statements to makeFirst and doLast as follows so that everything is clear:
task hello3(type: Exec) { doFirst { println 'start gradle....' } commandLine 'sh','sleep.sh' doLast { println 'end gradle....' } }
I believe Gradle is actually waiting for the script to complete before doing anything else, so you don't need to do anything special to make it wait.
Gradle will always run your shell script in a child process.
source share