Building a multi-module GWT project with Gradle


(Alex Sko) #1

I have a GWT project which I build with Gradle. now I want to split it into two Gradle modules: “platform” and “application” and then potentially add some other “application 2”. they should be all built together into a single WAR file. “application” and “application 2” should access platform’s classes, but should not know about each other.

what I did was: moved some “shared” and “client” classes from my current single module into the new “platform” module. created platform/src/<package_name>/platform.gwt.xml file, copied most of the stuff from my old application/…/xx.gwt.xml file to platform/…/platform.gwt.xml added ‘inherits name="<platform_package>…platform"’ to application/…/xx.gwt.xml file.

now there are two GWT modules, “applications” inherits the “platform”.

here’s my “application.gwt.xml”: https://gist.github.com/alexeyOnGitHub/9f9a21eebd11af45accd and here’s “platform.gwt.xml”: https://gist.github.com/alexeyOnGitHub/20a445b6a2327ca99164

IDEA properly compiles and executes this application just as it did before when it was a single GWT module. but Gradle build started to fail. my “gwtCompile” task is in the “application/build.gradle” and apparently it does not see the platform.gwt.xml file :

Loading inherited module ‘----.platform’

[ERROR] Unable to find ‘com/…/platform.gwt.xml’ on your classpath; could be a typo, or maybe you forgot to include a class

path entry for source?

[ERROR] Line 35: Unexpected exception while processing element ‘inherits’

com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)

how can I tell the GWT Compile task in Gradle to also include the “platform” module into the GWT compilation? I have this in the application/build.gradle

compile project(’:platform’) and it’s enough for Java Compile task in Gradle to see the classes from the “platform”, but GWT Compilation fails.

do I need to add a GWT Compilation task for the “platform” module as well?

I tried moving platform.gwt.xml file from “src” folder into “resources” and then Gradle does find it, but GWT compilation can’t find classes from “platform” module:

[ERROR] Errors in ‘file:/C:/projects/…/src/main/java/com/my/shared/workspace/WorkspaceUIBean.java’

[ERROR] Line 12: No source code is available for type com.my.shared.vcs.VCSConnectionInfo;

did you forget to inherit a required module?

[ERROR] Unable to find type ‘com.my.client.Module1’


(Alex Sko) #2

I found a solution:

def platformSources() {

return files(’…/platform/src/main/java’, ‘…/platform/src/main/resources’)

}

and then include “platformSources” into the GWT classpath:

classpath {

[

sourceSets.main.java.srcDirs,

// Java source

sourceSets.main.output.resourcesDir,

// Generated resources

sourceSets.main.output.classesDir,

// Generated classes

sourceSets.main.compileClasspath,

// Deps

platformSources()

]

}


Grade GWT applications