Using Gradle 4 Onwards with libGDX and GWT (HTML5)
So you are making your game work with the GWT export? Awesome
Oh you want to be using the latest Gradle version? Sweet!
Well you might find the default gradle build file generated by the libGDX setup tool, a touch outdated. You see, the Jetty plug has been deprecated in the latest version of Gradle (4+) and this used by the GWT gradle plugin to support the GWT Super Dev mode, a mode really useful for debugging HTML5/GWT oddities.
So how do we fix this?
Firstly, the way I approached this, was the right way for me - your mileage will vary.
First up we should change the Gradle plugin used for GWT, the current one used
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
Hasn’t been updated in 2 years! yikes!
Luckily there is a fork and an updated version lives on:
classpath 'org.wisepersist:gwt-gradle-plugin:1.0.1'
Next I completely rewrote the build file in the html directory:
apply plugin: "java" System.setProperty("user.home", "") import org.wisepersist.gradle.plugins.gwt.GwtSuperDev def HttpFileServer server = null def assetsLocation = "../core/assets" gwt {   gwtVersion = '2.8.0' // Should match the gwt version used for building the gwt backend   maxHeapSize = "8G" // Default 256m is not enough for gwt compiler. GWT is HUNGRY   minHeapSize = "1G"   src = files(file("src/")) // Needs to be in front of "modules" below.   modules 'com.mine.GdxDefinition'   devModules 'com.mine.GdxDefinitionSuperdev'   project.webAppDirName = 'webapp'   compiler {     strict = true;     disableCastChecking = true;   } } task startHttpServer() {   dependsOn draftCompileGwt   String output = project.buildDir.path + "/gwt/draftOut";   doLast {     copy {       from "webapp"       into output     }     copy {       from assetsLocation       into output + "/assets"     }     println 'start Http Server'     File root = new File(output);     SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()     server = factory.start(root, 9090)     println "Server started in directory " + server.getContentRoot() + ", port " + server.getPort()   } } task superDev(type: GwtSuperDev) {   dependsOn startHttpServer   doFirst {     gwt.modules = gwt.devModules   } } task dist(dependsOn: [clean, compileGwt]) {   doLast {     file("build/dist").mkdirs()     copy {       from "build/gwt/out"       exclude '**WEB-INF/**'       into "build/dist"     }     delete fileTree("build/dist") {       include "**/*soundmanager*.*"       include "**/logo.png"       include "**/clear.cache.gif"       include "**/hosted.html"     }     copy {       from "webapp"       into "build/dist"     }     copy {       from "war"       into "build/dist"     }     delete "build/dist/WEB-INF"   } } task addSource {   doLast {     sourceSets.main.compileClasspath += files(project(':core').sourceSets.main.allJava.srcDirs)   } } tasks.compileGwt.dependsOn(addSource) tasks.draftCompileGwt.dependsOn(addSource) sourceCompatibility = 1.8 sourceSets.main.java.srcDirs = ["src/"]
As you can see there are a lot of changes. The key points here are:
1: We use the built in SimpleHttpFileServer to allow for the files to be served, you see GWT starts it’s own Jetty instance for the code server - unsure what any of that means? check out the webpage - http://www.gwtproject.org/articles/superdevmode.html
2: No longer creating war files etc, we only need to deal in straight of Javascript so I ditched the need for the war creation.
3: Tied the superDev task to starting the httpFilerServer which in turn does a draft build (quicker, less optimized) of the javascript.
All in all a neat solution to allow a powerful feature










