Setup Maven for GWT development

In order to use gwt-maven-plugin, you will need to configure it using the plugin configuration in your POM, and you will need to decide how you want to handle GWT being present (automatic or manual mode - more below).

Configuring gwt-maven-plugin itself

Regardless of which "mode" you use, automatic, or manual, you also need to configure gwt-maven-plugin itself, of course.

Also, as a convenience it helps to define a property for the GWT version (so you can change it in one place later to upgrade).

For example:

    <properties>
       <gwt.version>1.6.4</gwt.version>
    </properties>

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
            <execution>
                <goals>
                    <!-- gwt:* goals to be executed during build -->
                </goals>
            </execution>
        </executions>
    </plugin>

Getting the Plugin

Getting the plugin is simple. It is deployed in maven default repository "central", so you don't have to do anything !

Handling GWT

The plugin needs to know where to find GWT (jars and native libraries). There are two ways you can do this.

  1. Use the Maven dependency plugin to automatically extract GWT native libraries from central repo (automatic mode)
  2. Download and unpack GWT yourself and set the google.webtoolkit.home plugin configuration property to the location where it is installed (manual mode)

Automatic Mode Setup

If you are going to do automatic setup, you need to include the GWT dependencies in your POM. The plugin will detect this version and use it internally.

For example:

  <!-- GWT dependencies (from maven "central" repo) -->
  <dependency>
    <groupId>com.google.gwt</groupId>
    <artifactId>gwt-servlet</artifactId>
    <version>${gwt.version}</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>com.google.gwt</groupId>
    <artifactId>gwt-user</artifactId>
    <version>${gwt.version}</version>
    <scope>provided</scope>
  </dependency>

Note : Don't define gwt-dev as project dependency : this JAR has many common libraries packaged that may conflict with the ones defined for your project, resulting in uncomprehensible NoSuchMethodErrors. The gwt-maven-plugin will automagically resolve the required dependency based on your declared gwt-user dependency.

Manual Setup

If you are going to setup GWT manually, for example if you want to test latest build or a patched one, you will need to first unpackage it (http://code.google.com/webtoolkit/download.html). Then, you will need to tell gwt-maven-plugin where GWT is. This can be done with the gwtHome plugin configuration parameter or the google.webtoolkit.home property (this property is unset for automatic mode, but required for manual mode).

  <property>
    <google.webtoolkit.home>C:/MyCustomGWT</google.webtoolkit.home>
  </property>

You can also use the $env.GWT_HOME syntax to refer to an OS environment variable.

For manual mode, you also need the GWT dependencies defined (these are required because plugins and goals other than gwt-maven-plugin need them, like the standard compiler).

Note that with manual mode, even though the dependencies are still needed, the difference is that the source of the dependencies can be your locally installed GWT location (GWT_HOME), rather than a Maven repository, and there is no separate step to unpack the native libraries (they are already in gwtHome).

For example:

  <property>
    <google.webtoolkit.home>${env.GWT_HOME}</google.webtoolkit.home>
  </property>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>custom</version>
        <scope>system</scope>
        <systemPath>${env.GWT_HOME}/gwt-servlet.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>custom</version>
        <scope>system</scope>
        <systemPath>${env.GWT_HOME}/gwt-user.jar</systemPath>
    </dependency>

    . . . .

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>compile</goal>
                    <goal>generateAsync</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

Configuring maven-war-plugin

Google Eclipse Plugin requires your web application to be created as an exploded WAR in /war (hard coded path). To match this requirement, you have two options :

  • Move your src/main/webapp folder to /war and configure maven-war-plugin warSourceDirectory parameter. This is the inplace setup, as the webapp source will be used to build the exploded WAR layout.
  • Configure maven-war-plugin to build the webapp in /war (webappDirectory parameter) instead of the standard outputDirectory.

    The gwt-maven-plugin has a boolean inplace parameter to configure the option you choose. The inplace mode is interesting if you use JSPs as no build/packaging/deployment is required to see changes made in the JSP file. Same applies to static files like CSS.