Permission error with Gradle on Travis CI

What happened?

I was setting up the continuous integration for a project that used Gradle as build tool on Travis CI.

The first build failed due to a repeated permission denied error running the gradlew wrapper file.

The important part it’s the following:

$ ./gradlew assemble
/home/travis/build.sh: line 179: ./gradlew: Permission denied

The command “eval ./gradlew assemble” failed. Retrying, 2 of 3.

/home/travis/build.sh: line 179: ./gradlew: Permission denied

The command “eval ./gradlew assemble” failed. Retrying, 3 of 3.

/home/travis/build.sh: line 179: ./gradlew: Permission denied

The command “eval ./gradlew assemble” failed 3 times.

The solution

Obviously the first thing to do is searching on google about the problem.

This lead me to this stackoverflow answer, from wich I used the second solution proposed.

Basically the problem is due to the fact that the the gradlew wrapper file it’s not set as executable.

I liked more the solution of adding a before_install call to chmod +x on the file in question.

So from this .travis.yml

I just ended up with:

Which is fine.

Bye.