Fork me on GitHub
NOTICE There is a new plugin (archetypes and eclipse integration), a fresh start that correctly support multi-module projects, it is not version-bounded with GWT, support multiples GWT versions and other fixes, improvements and best practices. This plugin is now considered the legacy GWT maven plugin (aka mojo GWT maven plugin) and the new one is considered the new generation GWT maven plugin (aka tbroyer GWT maven plugin). The legacy maven plugin is still supported but it is strongly encouraged to use the new one for new projects.

Project organization

Conventions

Compared to GWT Documentation on directory layout, the plugin follows Maven conventions:

Compared to the directory layout used by GWT, notice that the /war folder is replaced by the src/main/webapp folder, following maven-war-plugin conventions. The project structure generated by the gwt-maven-plugin archetype allready includes the adequate Google Plugin for Eclipse configuration. If you manually migrate a GWT project to Maven, you will need to configure the Google Plugin for Eclipse to use this folder.

POM configuration

In order to use gwt-maven-plugin, you will need to configure it using the plugins section of your POM.

You also need to include the GWT dependencies in your POM, and use the adequate gwt-maven-plugin version. The plugin will check this version and warn if you try to use inconsistent releases.

  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>2.8.1</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>2.8.1</version>
      <scope>provided</scope>
    </dependency>
  <dependencies>

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

Note : Don't define gwt-dev as project dependency : this JAR only contains gwt SDK tools and 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 and add it to classpath when lauching GWT tools.

Multi-project setup

Large Maven projects often are divided into sub-projects. This section describe the maven configuration needed to use such layout on GWT projects with gwt-maven-plugin. If you're not familiar with multi-module layout, please read first the related maven documentation.

NOTE that GWT also has a notion of module. Both Maven and GWT use the term module to define units of modularization. To a degree both concepts go hand in hand, as gwt-modules define boundaries at which Maven-modules might be cut. To not confuse these two terms though, for the rest of this section we will use the term module, if we talk about GWT-modules, in contrast to the term project, if we talk about Maven-modules.

First, we will setup a basic Maven project structure consisting of two sub-projects: one containing domain code and another one containing the actual GWT application. Like other web application, a common pattern is to separate GUI functionality from domain functionality (among others) :

parent/                                     (aggregating parent project)
|- pom.xml
|
|- domain/                                      (domain code, etc.; packaging: JAR)
|  |- pom.xml
|  \- src/main/java/
|     \- org/codehaus/mojo/domain
|        \- User.java
|
\- webapp/                                      (GUI code; packaging: WAR)
   |- pom.xml
   \- src/
      |- main/java/
      |  \ -org/codehaus/mojo/ui/
      |     |- Hello.gwt.xml
      |     \- client/Hello.java
      \- main/webapp/
         \- WEB-INF/web.xml

To convert the domain project to a valid GWT module, we add a module descriptor Domain.gwt.xml to the domain project that we can extend from our webapp Hello module.

|- domain/
|  |- pom.xml
|  \- src/main/java/
|     \- org/codehaus/mojo/domain/
|        \- User.java
|  \- src/main/resources/
|     \- org/codehaus/mojo/
|        \- Domain.gwt.xml                          (Additionnal gwt.xml module file)
<module>
  <inherits name="com.google.gwt.user.User"/>
  <source path="domain"/>
</module>

The domain project is not yet a valid GWT module: GWT compiler requires Java source files.

Configure Maven to package a sources JAR for domain project. In the webapp project, add a dependency to the ''sources JAR'' package:

<dependencies>
  <dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>domain</artifactId>
    <version>${project.version}</version>
    <classifier>sources</classifier>
    <scope>provided</scope>
  </dependency>
</dependencies>