If Maven is to build systems what Coca-cola is to beverages, Gradle can be considered as Pepsi: both are great, but it’s a matter of preference. Gradle is on the rise, and many developers and ops people see in Gradle the solution to their Maven problems. Maven is still the most used build system, but it could be taken over by Gradle, so GWT developers should know how to operate both. Gradle provides a plugin for GWT, and the setup is relatively simple. The goal of this post is not to make a comparison between Gradle and Maven performance, but to provide a brief explanation on how to configure Gradle for GWT projects.

In this tutorial, we are going to use the Gradle plugin developped by Steffen Schäfer: https://github.com/steffenschaefer/gwt-gradle-plugin, which can be considered as the official Gradle plugin. There is another plugin for Gradle: https://github.com/Putnami/putnami-gradle-plugin, but it won’t be covered in this tutorial.

To generate a simple java project in Gradle, you can use:

gradle init --type java-library 

which generate simple project structure with a build.gradle file.

We can then add our GWT plugin configuration to the build file.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
}
}

apply plugin: 'gwt'
apply plugin: 'war'

repositories {
jcenter()
}

repositories { mavenCentral() }

dependencies {
providedCompile('com.vaadin.polymer:vaadin-gwt-polymer-elements:1.7.0.0')
providedCompile('org.fusesource.restygwt:restygwt:2.2.0')
testCompile('junit:junit:4.11')
}
gwt {
gwtVersion='2.8.0'

modules 'com.example.gwtmodulename'

maxHeapSize = "1024M"

superDev {
noPrecompile=true
}
}

The minimal gwt configuration is pretty simple. After we configured our dependencies, we told the gwt plugin about our gwt version and the location of our gwt module. That’s all. We have also used the war plugin to package our application and copy the static resource.

Using the command: “gradle tasks”, we can list the set of commands/taks offered by the plugin:

GradleTasks

Gradle plugin offers also the possiblity to specify the type of project as either a gwt library or gwt application in the same way as the Maven net.ltgt.gwt.maven plugin. This can be done by specifying the type of plugin:

For a gwt library:

apply plugin: 'gwt-base'

For a gwt application:

apply plugin: 'gwt'

Another option to generate a GWT gradle project, is to use the GWT project generator which allows to preconfigure all the dependencies and to generate a ready to use project.

One of the pitfalls of the Gradle GWT plugin, is its lack of documentation. The official documentation is minimal and lacks clear examples and explanations.

To conclude, Gradle is a pretty simple build system to use and configure for GWT applications, and should be fairly simple to adopt or to convert to from an existing Maven project.

A Sample project can be found here: https://github.com/zak905/gradle-gwt-example