0

I've written a shell-script to build all projects mentioned in a particular file using a while loop and gradle clean build command to do so.

Here is how it looks like:

echo -e "\Building all projects"
filename="projects"      #File Containing all projects name to build
workdir=$(pwd)
while read -r line; do
    name="$line"
    echo -e "\ngradle build repo - $name"
    cd $workdir/$name
    gradle clean build 
done < "$filename"

Here is contents of projects file:

core
dal
dao
web
ui

and here is my directory structure

src
|-script.sh
|-core
|  |-build.gradle
|  |-gradle.properties
|  |-src
|  |-otherstuff
|
|-dal
|  |-build.gradle
|  |-gradle.properties
|  |-src
|  |-otherstuff
|
|-dao
|  |-build.gradle
|  |-gradle.properties
|  |-src
|  |-otherstuff
|
|-same repeats for web and ui

So I expect my script to read file projects and go into all the mentioned folders from that file and issue command gradle clean build in that folder.

Everything works fine and as expected except gradle command no matter whether build succeeds or fails for the first project (core) it makes script to break the loop and exit.

So It prints output only for the first project and doesn't work for all other.

However,

If I try to run it in the background it works fine; ie; instead of

gradle clean build

if I issue

gradle clean build &

It works fine; Although output, in that case, is gibberish.

Can anyone please look into this and help me out??

Thanks in advance.

Vedant Terkar
  • 4,553
  • 8
  • 36
  • 62
  • Have you thought about doing this the other way around? https://stackoverflow.com/questions/25562207/execute-shell-script-in-gradle – Allan Mar 20 '19 at 08:13
  • try forcing the return value of gradle to success: `gradle clean build || true`; however, most build system try to do it the other way round: stop early when a built-error appears... – umläute Mar 20 '19 at 08:31
  • @umläute, Already tried it; also tried to catch return value in `if` but with no luck :( . Also even if the `gradle build` runs without any error still it stops after the first iteration itself.. Don't know what is happening internally. – Vedant Terkar Mar 20 '19 at 10:01
  • try `gradle --console plain clean build & disown` – Michael Jaros Mar 20 '19 at 10:36
  • @MichaelJaros, Thanks For suggestion but it didn't helped as output is still gibberrish.. – Vedant Terkar Mar 21 '19 at 05:34
  • 2
    Thanks @tripleee, issuing `gradle --console plain clean build – Vedant Terkar Mar 25 '19 at 09:41

0 Answers0