Nov 7, 2008

Maven2 + GWT 1.5.3 + all platforms + tests

I think I finally managed our Maven setup to work.

Requirements:
  • Pom should work out of the box, not requiring GWT installation beforehand
Versions used:
  • GWT 1.5.3
  • Maven 2.0.9
Solution:
  • I downloaded the three distribution files from Goolge,
  • deleted the doc and sample folders
  • re-packaged them as jar files (gwt-dist-windows.jar, gwt-dist-linux.jar and gwt-dist-mac.jar)
  • deployed them to our public maven repository http://semweb4j.org/repo/com/google/gwt as
    com.google.gwt
    dist-windows
    1.5.3
In the pom.xml we need to find out on which platform we are. We use the following carefully crafted snipped to distinguish properly between windows, mac and linux. Note the subtle variations of using "name" or "family".

<!-- http://docs.codehaus.org/display/MAVENUSER/Profiles -->
<profiles>

<profile>
<id>mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<os>mac</os>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<name>linux</name>
</os>
</activation>
<properties>
<os>linux</os>
</properties>
</profile>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<os>windows</os>
</properties>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>dev-${os}</artifactId>
<version>${gwtVersion}</version>
<scope>system</scope>
<systemPath>
${basedir}/gwt/gwt-${os}-${gwtVersion}/gwt-dev-${os}.jar
</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>


Note the profiles achieves two things:
  • Set the ${os} property (this cannot be achieved otherwise)
  • Add a dependency to the gwt-dev jar - which must reside in the same directoy as some other OS-specific files.
We still need to make sure that the OS-specific part is at the right place (here: ${basedir}/gwt ) at the right time (here: before using the dependencies for compile or test).

Next we need to declare the GWT specific dependencies in the pom. We simply uploaded those to our public maven repository as well (http://semweb4j.org/repo)


<!-- gwt dependencies -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
</dependency>

Now comes the clever part:

<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>dist-${os}</artifactId>
<version>${gwtVersion}</version>
</dependency>

This instructs maven to fetch our special GWT-dist jar. We also need to unpack it at the right time, which is done here, in :

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-gwt</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.google.gwt</groupId>
<artifactId>dist-${os}</artifactId>
<version>1.5.3</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>
${basedir}/gwt
</outputDirectory>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>


Together these settings achieve our goals. Feedback welcome.

Sources considered can be found in delicious, tagged with maven2+gwt.

9 comments:

  1. Note to myself: I should install GWT in ${user.home}/gwt-${gwtVersion} and not in the project root. Otherwise several projects have their separate copy of GWT, just wasting disk space.

    ReplyDelete
  2. Well, I'm using gwt-maven-plugin from codehaus/mojo and I don't have to install GWT on my machine.

    ReplyDelete
  3. Hi Xavier, interesting. How can the plugin run the GEt howsted mode without the platform-specific GWT parts?

    ReplyDelete
  4. First of all, GWT is available on the main maven repository (http://repo1.maven.org/maven2/com/google/gwt/)

    Then you should try http://gwt-maven.googlecode.com/svn/docs/maven-googlewebtoolkit2-plugin/index.html
    which does this for you

    ReplyDelete
  5. with the profile part (same as you wrote)

    look at: http://gwt-maven.googlecode.com/svn/trunk/maven-googlewebtoolkit2-plugin/simplesample/pom.xml

    ~j3t

    ReplyDelete
  6. Hi,
    I'm the gwt-mojo developper. This one uses the same strategy you describe, and use a zip of natives libraries to be used by GWT for hosted mode. This zip is deployed on maven central with the other gwt artifacts.
    Cheers,
    Nicolas

    ReplyDelete
  7. I've been going this for a long time using the GWT Maven plugin on Google Code.

    See http://code.google.com/p/gwt-chronoscope for example. Today I build and test GWT apps across Linux, Windows, and OSX using JetBrains TeamCity continuous integration server. There is no need for any prior configuration of any machine.

    ReplyDelete
  8. Agree, the last gwt maven saves a lot of time by avoiding configuration like this, you really should try it !

    ReplyDelete
  9. Guys, thanks for the comments. I am convinces now to look much deeper into the GWT-maven plugin. It evolved very fast when we needed it, so we kept using some older version to get some stability into the build.

    ReplyDelete