Saturday, 31 October 2009

Configuring Maven-based GWT projects for Eclipse

When developing with GWT and maven in Eclipse, you don't get the benefits of the Google Eclipse Plugin by default, as maven and the Maven GWT plugin doesn't configure your Eclipse project settings to work with the GWT plugin. Here's how I changed my POM file to configure the Eclipse project correctly:
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-eclipse-plugin</artifactId>
      <configuration>
        <additionalProjectnatures>
          <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
        </additionalProjectnatures>
        <additionalBuildcommands>
          <buildcommand>com.google.gwt.eclipse.core.gwtProjectValidator</buildcommand>
        </additionalBuildcommands>
        <classpathContainers>
          <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
          <classpathContainer>com.google.gwt.eclipse.core.GWT_CONTAINER</classpathContainer>
        </classpathContainers>
        <excludes>
          <!-- These are provided by the GWT container -->
          <exclude>com.google.gwt:gwt-user</exclude>
          <exclude>com.google.gwt:gwt-dev</exclude>
        </excludes>
      </configuration>
    </plugin>
  </plugins>
</build>
If you're using GWT 1.x or earlier snapshots of GWT 2.0 you'll have to replace gwt-dev with gwt-dev-${platform}.

Now, when running mvn eclipse:eclipse, the Eclipse project will use the Google GWT plugin for the core GWT dependencies.

Tuesday, 27 October 2009

Building Maven artifacts for GWT 2.0.0 (trunk) and GWT Incubator

Update: Fixed svn url to GWT incubator.

Here's how I set up Hudson to run daily builds of the upcoming 2.0 version of GWT together with GWT Incubator:

I first set up a job 'GWT-2.0' to check out and build GWT itself. There are two repositories needed:

http://google-web-toolkit.googlecode.com/svn/trunk
and
http://google-web-toolkit.googlecode.com/svn/tools

Hudson then runs the following script to build GWT and deploy the maven artifacts to a local repository:
LOCAL_REPO=file:///srv/maven2
cd trunk
SVN_REV=`svn info | grep Revision | awk '{print $2}'`
GWT_VERSION=2.0.0-$SVN_REV
$ANT_HOME/bin/ant clean
$ANT_HOME/bin/ant -Dgwt.version=$GWT_VERSION

for artifact in `ls build/lib`;
do
artifact_packaging=${artifact##*.}
artifact_name=${artifact%.*}
$MAVEN_HOME/bin/mvn deploy:deploy-file -DgroupId=com.google.gwt -DartifactId=$artifact_name -Dversion=$GWT_VERSION -Dpackaging=$artifact_packaging \
-Durl=$LOCAL_REPO -DgeneratePom=true -Dfile=build/lib/$artifact
done

$MAVEN_HOME/bin/mvn deploy:deploy-file -DgroupId=com.google.gwt -DartifactId=gwt \
-Dversion=$GWT_VERSION -Dpackaging=zip -Durl=$LOCAL_REPO -DgeneratePom=true -Dfile=build/dist/gwt-$GWT_VERSION.zip

For GWT Incubator I trigger a build after each successful build of GWT. The Incubator repository is at

http://google-web-toolkit-incubator.googlecode.com/svn/trunk

After checking out, hudson runs the following script to build and deploy the Maven artifact:
LOCAL_REPO=file:///srv/maven2

export GWT_TOOLS=/home/hudson/.hudson/jobs/GWT-2.0/workspace/tools
GWT_SVN_REV=`svn info /home/hudson/.hudson/jobs/GWT-2.0/workspace/trunk/| grep \
Revision | awk '{print $2}'`
GWT_VERSION=2.0.0-$GWT_SVN_REV
export GWT_HOME=/home/hudson/.hudson/jobs/GWT-2.0/workspace/trunk/build/staging/gwt-$GWT_VERSION

cd trunk
$ANT_HOME/bin/ant -Dgwt.dev.jar=$GWT_HOME/gwt-dev.jar
$MAVEN_HOME/bin/mvn deploy:deploy-file -DgroupId=com.google.gwt -DartifactId=gwt-incubator \
-Dversion=$GWT_VERSION -Dpackaging=jar -Durl=$LOCAL_REPO -DgeneratePom=true -Dfile=build/dist/gwt-incubator.jar