2009-07-03

Building GWT application with Gradle

I wanted to check out Gradle in a small GWT application that we build for a very specific purpose. The Gradle version I've used is 0.61. Gradle has a plugin concept, but I haven't seen any GWT plugin for Gradle. The setup ended up being rather easy.

I defined a task which used ANT's Java task:

task gwtCompile << {
created = (new File(gwtBuildDir)).mkdirs()
ant.java(classname:'com.google.gwt.dev.Compiler', failOnError: 'true', fork: 'true') {
jvmarg(value: '-Xmx184M')
arg(line: '-war ' + gwtBuildDir)
arg(line: '-logLevel INFO')
arg(line: '-style PRETTY')
arg(value: 'me.trond.app.MyApp')
classpath {
pathElement(location: srcRootName + '/' + srcDirNames[0])
pathElement(path: configurations.compile.asPath)
pathElement(path: configurations.gwtCompile.asPath)
}
}
}


If you look at the classpath elements I've included a special configuration called gwtCompile. I had to define my own configuration:

configurations {
gwtCompile
}


This also had to be reflected in the dependencies:

dependencies {
...
gwtCompile (
[group: 'com.google.gwt', name: 'gwt-user', version: '1.6.4'],
[group: 'com.google.gwt', name: 'gwt-dev', version: '1.6.4', classifier: 'windows']
)
}


Since I use the war plugin for gradle I had to make sure that gwtCompile task got called before packaging up the war file:

war.dependsOn gwtCompile


Also ensured that the result of the gwtCompile got included in the war file:

war {
//Adds the JavaScript and resources compiled by the GWT compiler
fileSet(dir: file(gwtBuildDir) )
}

1 comment:

Brett Cave said...

There is a gwt plugin from markuskobler on github that works quite nicely as an alternative.

for my implementation of gwt compiling via a task on gradle-0.9, had to use sourceSets['main'].java.srcDirs.iterator().next() and sourceSets['main'].resources.srcDirs.iterator().next() as location pathElements (src/main/resources is where we stick the gwt.xml files), and if using a generator, also the compiled classes directory of sourceSets['main'].java.classesDir (and compileGwt then dependent on compileJava too)