Fixing Compilation in GWT4NB

By default GWT4NB recompiles all of your client code with the GWT compiler whether or not you’ve changed it. This is a time consuming (and sometimes irritating factor). After a recent discussion on the GWT dev mailing list (which I was away for most of), I decided to post the solution I use here and on the mailing list.

In your projects build.xml, just copy-and-paste the following:

<target name="-post-compile">
<property name="output.js" location="${build.web.dir}/${gwt.module}/${gwt.module}.nocache.js" />
</target>

<target name="debug" description="Debug project in IDE." depends="init,compile,compile-jsps,-do-compile-single-jsp" if="netbeans.home">
<property name="gwt.compile.unneeded" value="true" />
    <antcall target="dist"/>

    <nbdeploy debugmode="true" clientUrlPart="${client.urlPart}"/>
    <antcall target="connect-debugger"/>
    <antcall target="debug-connect-gwt-shell"/>
</target>

<target name="-pre-dist">
    <condition property="gwt.compile.unneeded">
        <and>
            <available file="${output.js}" />
            <uptodate>
                <srcfiles dir="${src.dir}" includes="**/client/**/*.java" />
                <mergemapper to="${output.js}" />
            </uptodate>
        </and>
    </condition>
    <antcall target="do-gwt-compile" />
</target>

<target name="do-gwt-compile" unless="gwt.compile.unneeded">
    <!-- You can override this property in the 'gwt.properties' file -->
<property name="gwt.compiler.output.style" value="OBFUSCATED"/>
<property name="gwt.compiler.logLevel" value="WARN"/>

    <java classpath="${javac.classpath}:${src.dir}" failonerror="true"
      classname="com.google.gwt.dev.GWTCompiler" fork="true" maxmemory="512m">
        <arg value="-out"/>
        <arg path="${build.web.dir}/"/>
        <arg value="-style"/>
        <arg value="${gwt.compiler.output.style}"/>
        <arg value="-logLevel"/>
        <arg value="${gwt.compiler.logLevel}"/>
        <arg value="${gwt.module}"/>
    </java>
<property name="gwt.output.dir" value="${gwt.module}"/>
    <move todir="${build.web.dir}/${gwt.output.dir}">
        <fileset dir="${build.web.dir}/${gwt.module}"/>
    </move>
</target>

What does it actually do? It checks to see if the client side code is newer than the module.nocache.js file in the web output. Since GWT overwrites this file every-time it compiles (and in GWT 1.5 actually deletes it first), it will only be older if one of your source files has changed.

Hope this helps you out, happy coding!

Edit 11/14/08: The script is now fixed to only build using normal javac when run in debugging mode.

Advertisements

7 Responses to “Fixing Compilation in GWT4NB”

  1. Javier Mena Says:

    Thanks… which implications do this code have?

  2. Jason Says:

    The XML above has two basic implications:

    1) If you don’t change client-side code, the GWT compiler will not be invoked. When you do change client-side code, the GWT compiler will be run to convert the code into JavaScript.

    2) The compiler is allocated up to 512mb of memory to avoid OutOfMemoryError s during compilation.

  3. Andy Byard Says:

    Nice one, this snippet of config has cut my average compile time from 3 minutes to just under a minute.
    I was having out of memory errors when trying gwt1.5 so i went back to 1.4.62. I might give 1.5 another try now.

  4. Arno.Nyhm Says:

    can you change the build.xml so that it only compile the server part and then start for debugging in GWTShell (where a client compile is not needed)

  5. Jason Says:

    Aron, I’ve modified the script to (hopefully) only use javac during debugging deployment. It will still run the client side sources through the javac compiler, but to me thats a good thing đŸ˜‰

  6. Derek Lewis Says:

    Thanks for the ant scriptlet, very useful avoiding GWT compilation when it’s not needed.

  7. Michael Powe Says:

    Hello,

    It seems that this fix no longer works. I’m using NB 6.8, GWT 2.0, the latest stable release of the plugin. The error is generated in build-impl.xml.

    Thanks.

    mp


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: