Sunday, February 20, 2022

Re: Building a GWT project in Eclipse 2019-03+ with Java 11.

description = 'GWT client'

ext {
buildWebapp = "${project(':projectname-web').buildDir}/generated/webapp"
gwtDev = Boolean.getBoolean('gwt.development')
}

sourceSets {
main {
java {
srcDir rpcSrc
srcDir exceptionsSrc
}
}
}

configurations {
gwt
}
dependencies {
api project(':projectname-api')
implementation "com.google.gwt:gwt-user:$gwtVersion"
implementation("com.github.branflake2267:gwt-maps-api:$googleMapsApiVersion") {
transitive = false
}
implementation "com.google.elemental2:elemental2-webstorage:$elementalVersion"
implementation "com.google.elemental2:elemental2-dom:$elementalVersion"
implementation "com.google.elemental2:elemental2-promise:$elementalVersion"

gwt(project(':projectname-api')) { transitive = false }
gwt files(project.sourceSets.main.java.srcDirs)
gwt files(project.sourceSets.main.resources.srcDirs)
gwt files(project(':projectname-common').sourceSets.main.java.srcDirs)
gwt files(project(':projectname-api').sourceSets.main.java.srcDirs)
gwt files(project(':projectname-api-core').sourceSets.main.java.srcDirs)
gwt "com.google.gwt:gwt-user:$gwtVersion"
gwt "com.google.code.gwtx:gwtx:$gwtxVersion"
gwt "com.github.branflake2267:gwt-maps-api:$googleMapsApiVersion"
gwt "com.google.elemental2:elemental2-webstorage:$elementalVersion"
gwt "com.google.elemental2:elemental2-dom:$elementalVersion"
gwt "com.google.elemental2:elemental2-promise:$elementalVersion"
gwt "com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion"
gwt "com.google.gwt:gwt-dev:$gwtVersion"
}

task compileGwt(type: JavaExec) {
dependsOn compileJava
ext {
outDir = "$buildWebapp/projectname.gwt"
}
group = 'Build'
description = 'Compile the GWT source'
inputs.files configurations.gwt
inputs.property 'development', gwtDev
outputs.dir outDir
classpath = configurations.gwt
mainClass = 'com.google.gwt.dev.Compiler'
args = []
args += ['-sourceLevel', "1.${project.parent.ext.javaVersion}"]
args += ['-war', buildWebapp]
args += ['-logLevel', 'INFO']
args += ['-workDir', "$buildDir/tmp/gwt"]
args += ['-XfragmentCount', '6']
args += ['-failOnError']
if (gwtDev) {
args += ['-style', 'PRETTY']
args += ['-draftCompile']
args += ['-optimize', '0']
args += ['-XmethodNameDisplayMode', 'ABBREVIATED']
args += ['org.projectname.ProjectNameDev']
} else {
args += ['-style', 'OBFUSCATED']
args += ['-optimize', '9']
args += ['-XnoclassMetadata']
args += ['org.projectname.ProjectName']
}
}
task cleanGwtTemp {
doLast {
ant.delete(dir: "$buildWebapp/projectname.gwt")
ant.delete(dir: "$buildDir/tmp/gwt")
}
}
cleanCompileGwt {
dependsOn cleanGwtTemp
}
clean {
dependsOn cleanGwtTemp
}

task gwtSuperDev(type: JavaExec) {
dependsOn compileJava
description = 'Run the GWT code server for Super Dev Mode'
classpath = configurations.gwt
mainClass = 'com.google.gwt.dev.codeserver.CodeServer'
args = []
args += ['-sourceLevel', "1.${project.parent.ext.javaVersion}"]
args += ['-launcherDir', buildWebapp]
args += ['-logLevel', 'INFO']
args += ['-workDir', "$buildDir/tmp/gwt"]
args += ['-precompile']
args += ['-failOnError']
args += ['-bindAddress', '0.0.0.0']
args += ['org.projectname.ProjectNameDev']

doFirst {
file("$buildDir/tmp/gwt").mkdirs()
}
}
We started using GWT in our project in 2009 (GWT 1.5.0!)
When we moved from Maven to Gradle in 2020 (one of the best decisions ever, because the project is complex, has a lot of code generation and Gradle's skipping of already executed tasks is a must - it was unbearable with Maven), we've also dropped the GWT Eclipse plugin altogether.
Also, we don't use a GWT plugin for Gradle either: instead, we just run either GWT codeserver or compiler via their main classes, setting up the classpath correctly.
To start with, as we already had multiple modules in the build system (api / impl / web, etc), we've split the GWT classes to a new module (no longer the web project).

Attached in this post is the anonymized and stripped down build.gradle file for the gwt module.

Finally, for us to be productive again in Eclipse, we've written a script that does the following:
  1. Delete the destination's nocache.js file
  2. Starts the code server via gradle, redirecting the output to a file
  3. Sleeps until the nocache.js file exists again
  4. Write the PID of the gradle process to a file
We run this from an Eclipse external tool, and have the tool's refresh option to refresh the web's project output dir. This way the publishing works flawlessly in Eclipse with a Tomcat server.

We've also created other 2 similar scripts / Eclipse tools: one to stop the codeserver (kill the process with the PID indicated in the file) and another one to show the codeserver log (tail -f1000 -n in the output file).

We'll never look back to neither the Eclipse plugin (which did many other things we don't use) nor to a Gradle plugin (which were mostly written once and abandoned, and Gradle evolves fast, introducing breaking changes, and that broke the project more than once).

Em domingo, 20 de fevereiro de 2022 às 08:33:18 UTC-3, t.br...@gmail.com escreveu:
On Saturday, February 19, 2022 at 1:57:16 AM UTC+1 tequil...@gmail.com wrote:
Hi Jasper

I'll be just glad if my current progress saves someone's time.
I progress on step by step basis, so far I succeeded in Eclipse build and debugging.

Most of my problems were caused by combination of JDK11+ (namely modules) + Gradle + Eclipse + Eclipse GWT Plugin. 

Reason: GWT SDK gwt-dev.jar contains lot of classes that must not be visible to Eclipse compiler, but in fact they are, causing dreaded "The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml" error.
When `gradle build` is issued in command line the gwt-dev.jar from the maven repository is linked, it contains exactly essential google classes and nothing more. Thus the build succeeds.

But when you import such project in Eclipse under JDK11+ (I use JDK17) and select a GWT SDK there're lots of build errors caused by "The package is accessible from more than one module"

Can't you somehow disable the module path or put all dependencies in the classpath rather than the module path?

Alternatively, how about not using the Eclipse GWT Plugin?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/5974a25e-6e59-435c-b7af-05d1b4e038f2n%40googlegroups.com.

No comments:

Post a Comment