Gradle plugin to support GWT related tasks.
The plugin supports GWT 2.x only (GWT 1.x isn’t supported at all). Main testing was done with GWT 2.5 but it should work with older versions too. The plugin is developed with Gradle 1.7 but should also work with Gradle 1.6. Due to used APIs it definitely won’t work with Gradle versions before 1.6.
The plugin is designed to work with the following principles in mind (but can be configured to work different): * The webapp source (typically /src/main/webapp) is holy and won't be polluted with generated stuff. Instead a special working dir is set up with an exploded template of the webapp (typically /war) * Compilation is done with a dedicated output folder to make incremental builds work * All output is configured to be written to “${buildDir}/gwt” with several sub directories for different purposes (look at the chapter “Default directory structure” for details)
Plugin binaries can be found in a Maven repository hosted at GitHub (URL: http://dl.bintray.com/steffenschaefer/maven). You can browse this repository here.
To build a version on your own, simply run "gradle publish" in the root directory of the code repository. After the build finished, a directory named "repo" will appear. This directory is a maven repository containing the plugin binaries. You can copy this directory to your project and use it as local repository.
To configure your project to apply the plugin using the maven repository hosted at GitHub, you need the following:
| buildscript {
repositories {
maven {
url 'http://dl.bintray.com/steffenschaefer/maven'
}
mavenCentral()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.2'
}
}
|
Supposed you already applied the gradle "war" plugin to your project, you have to also apply the "gwt" plugin:
| apply plugin: 'war'
apply plugin: 'gwt'
|
Now you have to configure the GWT modules to compile into your web application:
| gwt {
modules '<YOUR-GWT-MODULE>'
}
|
If you want to use automatically configured GWT dependencies (gwt-dev, gwt-user, ...) you have to extend the configuration to set the desired GWT version:
| gwt {
gwtVersion='2.5.1'
modules '<YOUR-GWT-MODULE>'
}
|
This chapter describes what the plugin adds to your project and which default settings are changed.
Using the default configuration, the plugin will use the following directory structures:
An extension with name “gwt” of type de.richsource.gradle.plugins.gwt.GwtPluginExtension. For details on how to configure the plugin, please refer to the chapter “Plugin configuration”. Alternatively you can have a look at the source code of this class to check what can be configured.
A configuration named “gwt” is added. This configuration should be used for all dependencies that are only needed by GWT itself (e.g. gwt-dev.jar). Dependencies associated with this configuration with be available at compile time but not at runtime.
The plugin at least configures the following tasks:
If your project uses the “gwt” plugin together with the “war” plugin the following changes will happen:
If your project uses the “gwt” plugin together with the “eclipse” plugin the following changes will happen to your eclipse configuration:
If your project uses the “gwt” plugin together with the “eclipse” and “war” plugins the following changes will happen to your eclipse configuration (additionally to the ones described above):
When running the task “gwtDev” you can specify a system property “-DgwtDev.debug=true” to enable debugging. This causes the build to stop when starting development mode and waiting for a debuger to attach to port 5005. Now you can configure your IDE to connect to that debug port.
Be aware that the Super Dev Mode is ony available GWT 2.5+. Additionally be aware that Super Dev Mode requires specific browsers to work!
This chapter does not describe the usage of “Super Dev Mode” in detail. Please refer to the official documentation to learn how to use it. Be aware that you need to adjust your *gwt.xml” file or provide a special one for development.
In contrast to the “normal” Development Mode, the Super Dev Mode does not start the complete web application for you. Instead you have to run the web application by yourselves. Please refer to the chapter “Running the draft war” for details on how to startup the draft war using a servlet container.
To start the Super Dev Mode, execute the task “gwtSuperDev”. When it is ready you will see the message “Next, visit: http://localhost:9876/”. Do exactly that and open “http://localhost:9876/” in your browser. You will now see two Buttons “Dev Mode On” and “Dev Mode Off”. Drag&drop these to your browser’s bookmark bar.
Now navigate your browser to the webapp hosting your application. Press the “Dev Mode On” bookmark. Now you should see a dialog listing all your gwt modules. Select the one you want to debug. The page will reload after the Super Dev Mode recompiled your GWT module. You can now debug the application using the developer tools of your browser.
The following chapters describe usual use-cases and how do adjust the configuration accordingly.
The plugin can automatically add the needed GWT dependencies for you. Everything you have to do is: * Provide a repository where the GWT artifacts are hosted. If you haven’t already configured a repository and you want to use the Maven central repositroy, add the following to your build.gradle file: repositories { mavenCentral() } * Define the GWT version. To do that, insert the following configuration to your “build.gradle” file: gwt { gwtVersion='2.5.1' }
The plugin applies the default optimization settings but that can be adjusted. The following example shows how to adjust some of the flags (please refer to the official documentation on what these flags do):
| gwt {
compiler {
enableClosureCompiler = true; // activates -XenableClosureCompiler
disableClassMetadata = true; // activates -XdisableClassMetadata
disableCastChecking = true; // activates -XdisableCastChecking
}
}
|
As described before, the plugn adds a task “draftWar” to create a war file with a draft-compiled version of your GWT modules. This war can simply be run in a servlet container of your choice. But it’s also possible to do that using Gradle. The following chapters will show examples, how to configure different gradle plugns to do that for you.
Assumed that you added this plugin with “apply plugin: 'jetty'”, you can define a task “jettyDraftWar” with the following configuration:
| task jettyDraftWar(type: JettyRunWar) {
dependsOn draftWar
dependsOn.remove('war')
webApp=draftWar.archivePath
}
|
Simply run that task and navigate your browser to [http://localhost:8080/].
The cargo plugin is not a standard plugin shipped with gradle itself. You can read more about it on (GitHub)[https://github.com/bmuschko/gradle-cargo-plugin]. Assumed that you configured the servlet container of your choice using the documentation of the cargo plugin, you can add the draft war to it by adding the following configuration:
| cargo {
deployable {
file = tasks.draftWar.archivePath
context = 'draft'
}
}
|
If you want the cargo plugin to automatically build the draft war when executed, add the following to the end of your “build.gradle”:
| afterEvaluate {
tasks.cargoStartLocal.dependsOn(tasks.draftWar)
tasks.cargoRunLocal.dependsOn(tasks.draftWar)
}
|