Wednesday, May 12, 2010

The Gradle Wrapper

Who hasn't come across build system version incompatibilities? You build your system with Maven 2.0.X and one of your colleagues with 2.0.Y, and one of your builds break. Gradle provides a way to circumvent this, the Gradle Wrapper.

In Gradle you can have your project generate a gradle wrapper (gradlew) which you can commit to your repository. All subsequent build(er)s should then just execute:

$ ./gradlew

But how do you generate this? In the new gradle 0.9, the following snipplet generates the wrapper for you:

task wrapper(type: Wrapper) {
gradleVersion = '0.9-preview-1'

When you as the build-master now execute gradle wrapper, the buildprocess will generate the following files in the project:

  • gradle-wrapper.jar


  • gradlew

  • gradlew.bat

Now what does executing the gradlew command do? It first determines whether you have the right version (if any) installed of Gradle. If you do not have that, it downloads it for you. Once that's done, it will build the project using the right version of Gradle, all the time! If the build-master decides that the Gradle version should be bumped, he can edit the task and generate a new wrapper. Each of the people building the project then automatically pick this up.

No comments:

Post a Comment