tbroyer / gwt-maven-plugin

Starting fresh on building GWT projects with Maven
https://tbroyer.github.io/gwt-maven-plugin/
Apache License 2.0
167 stars 39 forks source link

Multi-module maven setup #127

Closed randymay closed 5 years ago

randymay commented 5 years ago

Currently, I have a multi-module maven application that builds several jars (including emulated classes), and ultimately, a GWT web application. This is all being done using Mojo's GWT plugin.

I am looking to take advantage of this plugin's multi-module support, but I am having trouble getting the gwt:codeserver goal running properly. I am convinced this is a configuration problem, and I'm not sure what the configuration is supposed to be.

Some questions I have are: At which level should I be executing this goal at? (By the looks of the documentation, it should be at the root project (i.e. the 'pom' type), but what configuration should go into the root pom? If all jars are going to be used as source for the gwt-app module, then should they all have the gwt-lib type?

Is there documentation to help with working on projects of this type? Thanks in advance.

tbroyer commented 5 years ago

At which level should I be executing this goal at? (By the looks of the documentation, it should be at the root project (i.e. the 'pom' type), but what configuration should go into the root pom?

Configuration for codeserver or devmode should go in the root POM, as they are aggregator goals, but it only defines arguments to pass to GWT (such as launcherDir and sourceLevel), and possibly (but not necessarily, as there are reasonable defaults) which Maven modules are your GWT applications (through projects and/or modules). The dependencies will be resolved from those GWT applications. See https://github.com/tbroyer/gwt-maven-archetypes for example configurations.

If all jars are going to be used as source for the gwt-app module, then should they all have the gwt-lib type?

See https://tbroyer.github.io/gwt-maven-plugin/ (and https://tbroyer.github.io/gwt-maven-plugin/codeserver.html)

gwt-lib should only be used for entirely client-side libraries (well, unless you're OK shipping source files with your server apps). Shared libraries should use standard jar packaging, as well as provide their sources in an additional artifact. You can also make a gwt-lib that depends on that JAR and sources-JAR, and adds GWT-specific files (the *.gwt.xml for instance), and I'd say this should be the rule rather than the exception (the exception being for a project with client+shared+server modules sharing the same packages, where the client's *.gwt.xml can then declare the shared sources as <source>). See https://github.com/tbroyer/gwt-maven-plugin/tree/master/src/it/e2e for an example (here, shared-gwt depends on shared:jar and shared:sources-jar, but also on model-gwt, which itself depends on model:jar and model:sources-jar; whereas shared depends only on model:jar) image (I really need to add this image to the repo somewhere)

Is there documentation to help with working on projects of this type?

Everything will be on https://tbroyer.github.io/gwt-maven-plugin/ with working examples (in the form of Maven archetypes) at https://github.com/tbroyer/gwt-maven-archetypes/

I'm closing this issue but if you have more specific questions/issues, please do not hesitate to continue the discussion here (closed does not mean "locked" or "ignored" :wink:)

randymay commented 5 years ago

Thanks so much for your detailed response; it was very helpful.

I am still struggling with having the plugin be made aware of the source code for non gwt-lib modules (i.e. jar modules). From the documentation, it looks like I need to add the dependency with the sources tag, but this doesn't seem to be making the source available.

Is adding the dependencies with source tag the the recommended approach? If so, which pom.xml are these dependencies supposed to be? In the root pom, or in one with gwt-app? Do these dependencies also have to be in gwt-lib modules?

I'm sure I could add additional source roots in the plugin's configuration, but we have several jars which are needing to provide source, so this approach is less than ideal.

Thanks in advance.

tbroyer commented 5 years ago

gwt-lib represents two things (same as jar, war, and pom represent two things in Maven):

If you have JARs that include sources, for GWT consumption (this definition would even include gwt-user), then <type>gwt-lib</type> is "semantically correct". For external dependencies, that's no different from <type>jar</type> (the default when not specified), as the plugin only actually cares about projects from the reactor. One way to create such a JAR is to use the gwt-lib lifecycle, but it's not the only way.

When you have shared libraries, you'd probably prefer not deploying sources to your servers, so you'd rather create JARs that don't include the sources, and package source JARs as additional artifacts; using the maven-source-plugin. You'd then, from a gwt-lib or gwt-app module (I'm talking packagings here), add dependencies to both the "normal" JAR and the sources JAR (using <classifier>sources</classifier>), as explained here.

I'd suggest running with debug logs (mvn -X), the plugin will then show more information about the dependencies and whether it added/found the sources or not. You'll also see the full classpath for launching the devmode, as well as the arguments, so you can check whether everything you need is included or not (for gwt:codeserver, sources are passed as arguments rather than in the classpath).

randymay commented 5 years ago

With your help, I was able to fix the problem.

I has listed my server project in my list, and that was not allowing the source to get picked up.

Thanks again for your help!