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/build.sh: 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
jdk:
  - oraclejdk7
  - openjdk7

before_install:
 - chmod +x gradlew

And my builds are nice and green again.

Advertisements

7 thoughts on “Using Travis CI with Gradle Wrapper

  1. 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… :-)

  2. 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: http://stackoverflow.com/questions/6476513/git-file-permissions-on-windows-7
    >
    > Great to have you using Travis CI.
    >
    > Have a wonderful day!
    >
    > —
    > Hiro Asari
    > support@travis-ci.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s