Using Travis CI with Gradle Wrapper

These days, I use gradle as build system in all of my projects. More precisely, I use the gradle wrapper, as it makes installation even more easy. You don’t even have to have gradle installed, Java is enough. The wrapper is a shell or bash script, depending on the OS, and downloads gradle along with all dependencies on execution. This makes the gradle wrapper very convenient for developing command-line tools, which is what most of my projects are at the moment.

I also like to integrate my projects with Travis CI, a free continuous integration environment for open source projects. Travis CI is quite powerful, but I also found it to be quite hard to get working properly, due to non-intuitive error messages I got for my builds. Nevertheless, it helps you to get rid of any environment-specific configuration and thus makes sure that somebody who checks out your project can get it running very easily. Essentially, you add a file named .travis.yml to your project in which you describe your build and then link your project with Travis CI.

So far, Travis CI worked easily with the gradle wrapper. Today, however, I upgraded gradle to 1.8 for several projects and mysteriously builds started to fail. Even older builds, that were fine with Travis CI at the time suddenly produced errors on repetition. I haven’t looked deeper at what changed on Travis’ side, but it seems that they did work on the gradle wrapper integration a few days ago and that supposedly broke my builds. The builds suddenly produced this error:

/home/travis/ line 41: ./gradlew: Permission denied

The command "./gradlew assemble" failed. Retrying, 2 of 3.

Huh, what happen to the execution permissions of the gradle wrapper? The only source that I could find that reported a similar problem was this blog post. The solution there was to explicitly set the execution permissions for the wrapper before the execution of the tests. This didn’t work for me, as my build failed even before, when trying to get the dependencies, aka the assemble step. So, I had to set the permissions before this step, and the build worked again. Setting permissions works with the well-known chmod executed with a specific hook, named before_install. As a summary, here is a working .travis.yml file for one of my projects:

language: java
  - oraclejdk7
  - openjdk7

 - chmod +x gradlew

And my builds are nice and green again.

7 thoughts on “Using Travis CI with Gradle Wrapper

  1. Issue solved… thanks to the Travis CI support and stackoverflow.

    Here the original answer from Travis CI support:

    Am 08.12.2014 16:11, schrieb Travis CI Support:
    > Hi, Peti,
    > Personally, I recommend turning on the execute bit for this file and committing it to your git repository instead of doing it in .travis.yml. If you are on Windows, take a look at this Stack Overflow question:
    > Great to have you using Travis CI.
    > Have a wonderful day!
    > —
    > Hiro Asari

  2. Thanks for sharing! I did run in the exactly same problem today. Your solution worked fine for me, too.

    I sent an Email to the travis-people and asked them, if this is not a tiny bug… :-)

Comments are closed.