James Williams
LinkedInMastodonGithub

Building HTML5 PlayN Apps with Gradle

Tags: HTML5 Groovy

In the previous post, we setup a PlayN application with Gradle and worked through building the desktop Java version. In this post, we'll continue our work and build the HTML5(GWT) project.

  1. Add our HTML project to settings.gradle.

    We need to tell gradle that we have a new subproject to deal with. All we need to do is modify the settings.gradle file to the one-liner below.

    include "core", "java", "html"

  2. Compile and install the Gradle GWT plugin.

    Clone the repo from gwt-repo. Run gradle jar to build a jar of the plugin. The jar will be located under the build/libs directory. Move this jar to /lib/plugins and this will be available system-wide for our builds.

  3. Do some file shuffling.

    The GWT plugin doesn't seem to properly import the core libraries as the Java project does. There are a couple ways of working around this like creating a task to copy over the core source files and resources to the proper place. I just did it by hand but a more modular solution would use tasks. I copied the core source files to src/main/java and the images resources to the src/main/webapp. A bit hacky I know.

  4. Creating the build.gradle file.

    Most of this is stock from the documentation with the GWT Gradle plugin however there are a couple additions. To the dependencies, I added

    gwt group: 'com.googlecode.playn', name : 'playn-html', version: playN_version

and the following to the end of the file

gwtModules     = ['playn.sample.hello.HelloGame']

You can find out the nitty gritty of the full gradle file here.

The GWT target adds a couple GWT-specific tasks, compileGwt and gwtDevMode, to build the GWT targets and launch Dev mode, respectively. Because a GWT compile can involve multiple passes and be time-consuming, running the dev mode server doesn't automatically compile the GWT code. gwtDevMode launches a local server to test the application. Debugging is enabled so beware, it may be slow.

Also in the gradle script is the jetty plugin enabling you to create a war file or start/stop a Jetty server. It seems to generate the war file fine but the built-in Jetty doesn't seem to run it properly.