Multiple GWT modules in one Maven module

1,025 views
Skip to first unread message

Frederik Van Hoyweghen

unread,
May 8, 2017, 12:18:06 PM5/8/17
to GWT Users
Hey everyone,

We are currently migrating our project away from using Ant, to Maven.

Along with this migration, we also tried to follow some of the project structuring that is recommended for a maven project.

Our Maven GWT module contains multiple GWT modules, but I'm struggling with making this work using Thomas Broyer's GWT plugin: https://github.com/tbroyer/gwt-maven-plugin
I feel like this was designed specifically with the idea of having only 1 GWT module inside a Maven module (please correct me if I'm wrong).


At first I tried this plugin configuration:
<configuration>
   
<skipModule>true</skipModule>
   
<modules>
       
<module>
           
<moduleName>A</moduleName>
            <moduleName>B</moduleName>
            <moduleName>C</moduleName>
            <moduleName>D</moduleName>
       
</module>
   
</modules>
</configuration>


This doesn't work because ModuleName has to be underneath the <configuration> tag.
Listing the modules underneath the <configuration> tag also doesn't work, running gwt:compile only compiles the last module in the list:

<configuration>
   
<moduleName>A</moduleName>
   
<moduleName>B</moduleName>
   
<moduleName>C</moduleName>
   
<moduleName>D</moduleName>
   
<skipModule>true</skipModule>
</configuration>



Does anyone have any experience with this?

Thomas Broyer

unread,
May 8, 2017, 12:46:56 PM5/8/17
to GWT Users


On Monday, May 8, 2017 at 6:18:06 PM UTC+2, Frederik Van Hoyweghen wrote:
Hey everyone,

We are currently migrating our project away from using Ant, to Maven.

Along with this migration, we also tried to follow some of the project structuring that is recommended for a maven project.

Our Maven GWT module contains multiple GWT modules, but I'm struggling with making this work using Thomas Broyer's GWT plugin: https://github.com/tbroyer/gwt-maven-plugin
I feel like this was designed specifically with the idea of having only 1 GWT module inside a Maven module (please correct me if I'm wrong).

That's right.
 
At first I tried this plugin configuration:
<configuration>
   
<skipModule>true</skipModule>
   
<modules>
       
<module>
           
<moduleName>A</moduleName>
            <moduleName>B</moduleName>
            <moduleName>C</moduleName>
            <moduleName>D</moduleName>
       
</module>
   
</modules>
</configuration>


This doesn't work because ModuleName has to be underneath the <configuration> tag.
Listing the modules underneath the <configuration> tag also doesn't work, running gwt:compile only compiles the last module in the list:

<configuration>
   
<moduleName>A</moduleName>
   
<moduleName>B</moduleName>
   
<moduleName>C</moduleName>
   
<moduleName>D</moduleName>
   
<skipModule>true</skipModule>
</configuration>



Does anyone have any experience with this?

David

unread,
May 9, 2017, 3:55:15 AM5/9/17
to google-we...@googlegroups.com
In my project I have many modules. What I did is simple create a gwt-lib maven module per GWT module. Those modules served different purposes so it made sense to split them in smaller artifacts.

In some cases I moved the code around so that I join multiple modules into one big module instead.

Another solution you could try is to have one module that inherits all the other modules. But I don't like that approach because it means you have manually maintain that gwt.xml file and those other gwt.xml files as well, while with the gwt-lib approach the gwt maven plugin will take care of adding the inherits tags automatically (if you have the gwt-lib in your dependency section).

--
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-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Frederik Van Hoyweghen

unread,
May 9, 2017, 5:27:25 AM5/9/17
to GWT Users
Thanks for the replies.

I already took a look at the issue on the plugin's github: https://github.com/tbroyer/gwt-maven-plugin/issues/57
Sadly, this was closed and recently labeled with a wontfix, hence me asking for help here :)


On Tuesday, May 9, 2017 at 9:55:15 AM UTC+2, DavidN wrote:
In my project I have many modules. What I did is simple create a gwt-lib maven module per GWT module. Those modules served different purposes so it made sense to split them in smaller artifacts.

In some cases I moved the code around so that I join multiple modules into one big module instead.

Another solution you could try is to have one module that inherits all the other modules. But I don't like that approach because it means you have manually maintain that gwt.xml file and those other gwt.xml files as well, while with the gwt-lib approach the gwt maven plugin will take care of adding the inherits tags automatically (if you have the gwt-lib in your dependency section).

I was hoping to (for the time being) avoid this exact approach. I realize this is the way to go, but I'm also expected to maintain full compatibility with our old ant build (until the maven build is as good as ready).

Should I take a look at the legacy Mojo maven plugin, or can I expect to come across the same hurdles with that one given my project layout?


Thomas Broyer

unread,
May 9, 2017, 6:22:40 AM5/9/17
to GWT Users


On Tuesday, May 9, 2017 at 11:27:25 AM UTC+2, Frederik Van Hoyweghen wrote:
Thanks for the replies.

I already took a look at the issue on the plugin's github: https://github.com/tbroyer/gwt-maven-plugin/issues/57
Sadly, this was closed and recently labeled with a wontfix, hence me asking for help here :)

My first comment on this issue tells you how to do it. In case it isn't clear, what I meant there is:

<executions>
  <execution>
    <id>compile-module1</id>
    <goals>
      <goal>compile</goal>
    </goals>
    <configuration>
      <moduleName>com.example.module1.Module1</moduleName>
      <moduleShortName>module1</moduleShortName>
    </configuration>
  </execution>
  <execution>
    <id>compile-module1</id>
    <goals>
      <goal>compile</goal>
    </goals>
    <configuration>
      <moduleName>com.example.module2.Module2</moduleName>
      <moduleShortName>module2</moduleShortName>
    </configuration>
  </execution>
</executions>

Another possibility (if you really do want to fork one and only one GWT compiler process) is to use the exec-maven-plugin's exec goal (though you would have to declare your source roots as resources dirs to get your sources copied to target/classes so they're present in the computed <classpath/>).
(I suppose you could get something working by "hacking" into the <compilerArgs>, and probably then <forceCompilation>true</forceCompilation> as you'd have the staleness check only take the module configured in <moduleName>/<moduleShortName> into account; I would discourage such "hack" though)

Frederik Van Hoyweghen

unread,
May 9, 2017, 6:33:57 AM5/9/17
to GWT Users
This indeed seems to be what I was looking for, thank you.
Are there any obvious downsides to doing it like this, with multiple executions?

Does it matter which specific moduleName I specify within the <configuration> tag, or should I just pick 1 arbitrary one there and put the others within the <executions> tag?

I very much appreciate the responses and the patience ;)

Thomas Broyer

unread,
May 9, 2017, 6:59:17 AM5/9/17
to GWT Users


On Tuesday, May 9, 2017 at 12:33:57 PM UTC+2, Frederik Van Hoyweghen wrote:
This indeed seems to be what I was looking for, thank you.
Are there any obvious downsides to doing it like this, with multiple executions?

Each module compilation will fork a new GWT compiler process, rather than use a single process compiling all modules (assuming that's how you're doing it in Ant), so it'll probably take more time (but possibly less memory).
That's all I can think of.
 
Does it matter which specific moduleName I specify within the <configuration> tag, or should I just pick 1 arbitrary one there and put the others within the <executions> tag?

I wouldn't put any <moduleName> / <moduleShortName> into the plugin-level <configuration>, and only put them into the <executions>.

Frederik Van Hoyweghen

unread,
May 9, 2017, 7:11:04 AM5/9/17
to GWT Users


On Tuesday, May 9, 2017 at 12:59:17 PM UTC+2, Thomas Broyer wrote:

I wouldn't put any <moduleName> / <moduleShortName> into the plugin-level <configuration>, and only put them into the <executions>.

That's what I figured, but it seems to be a required property (The parameters 'moduleName' for goal net.ltgt.gwt.maven:gwt-maven-plugin:1.0-rc-7:compile are missing or invalid, when invoking gwt:compile).

I defined my executions as per your example:
<configuration>
   
<localWorkers>6</localWorkers>
   
<skipModule>true</skipModule>
   
<draftCompile>true</draftCompile>
</configuration>
<executions>
   
<execution>
       
<id>compile-common</id>

       
<goals><goal>compile</goal></goals>
       
<configuration>

           
<moduleName>com.test.common</moduleName>
       
</configuration>
   
</execution>

etc.. but it appears the executions aren't triggered (or is this an effect of the missing moduleName under configuration?). It seems I have much to learn still.

Thomas Broyer

unread,
May 9, 2017, 7:26:28 AM5/9/17
to GWT Users


On Tuesday, May 9, 2017 at 1:11:04 PM UTC+2, Frederik Van Hoyweghen wrote:


On Tuesday, May 9, 2017 at 12:59:17 PM UTC+2, Thomas Broyer wrote:

I wouldn't put any <moduleName> / <moduleShortName> into the plugin-level <configuration>, and only put them into the <executions>.

That's what I figured, but it seems to be a required property (The parameters 'moduleName' for goal net.ltgt.gwt.maven:gwt-maven-plugin:1.0-rc-7:compile are missing or invalid, when invoking gwt:compile).

How are you invoking gwt:compile? If on the command-line, then the execution ID matters, and only one such execution will match (the one with <id>default-cli</id>). But starting with Maven 3.3.1 you can specify the execution id on the command-line too: "mvn gwt:compile@compile-common gwt:compile@compile-foo".


I defined my executions as per your example:
<configuration>
   
<localWorkers>6</localWorkers>
   
<skipModule>true</skipModule>
   
<draftCompile>true</draftCompile>
</configuration>
<executions>
   
<execution>
       
<id>compile-common</id>
       
<goals><goal>compile</goal></goals>
       
<configuration>
           
<moduleName>com.test.common</moduleName>
       
</configuration>
   
</execution>

etc.. but it appears the executions aren't triggered (or is this an effect of the missing moduleName under configuration?). It seems I have much to learn still.

Rule of thumb: if a goal is (meant to be) bound to a lifecycle phase (such as gwt:compile which is bound by default to the prepare-package phase; see https://tbroyer.github.io/gwt-maven-plugin/compile-mojo.html; but not gwt:devmode or gwt:codeserver for example), then invoke the lifecycle phase, not the goal.
Another rule of thumb: only ever invoke the lifecycle phases "package" and "verify" (and "install" and "deploy" when dealing with libraries, to share them with other projects / people). If you want to skip tests, pass -DskipTests, if you want to skip the compilation of tests too then pass -Dmaven.test.skip.
If you know what you're doing, then feel free to break those rules; if you know what you're doing.

Also, have a look at Gradle rather than Maven, if that's a possibility for your project(s).

Frederik Van Hoyweghen

unread,
May 9, 2017, 7:45:00 AM5/9/17
to GWT Users
I tried both the command line (mvn gwt:compile) and via the IntelliJ Maven plugin.
Indeed, binding the execution to the prepare-package phase and running mvn gwt:compile@compile-common works, and I'm glad it does.

If I'm reading what you're saying correctly, this means that there is no way to invoke all the plugin executions with a simple command?
I personally expected mvn gwt:compile to invoke everything it needs (so everything that comes earlier in it's lifecycle, including the executions I bound to the prepare-package phase),
or am I missing something obvious?

Thanks again!

Thomas Broyer

unread,
May 9, 2017, 8:18:16 AM5/9/17
to GWT Users


On Tuesday, May 9, 2017 at 1:45:00 PM UTC+2, Frederik Van Hoyweghen wrote:
I tried both the command line (mvn gwt:compile) and via the IntelliJ Maven plugin.
Indeed, binding the execution to the prepare-package phase and running mvn gwt:compile@compile-common works, and I'm glad it does.

If I'm reading what you're saying correctly, this means that there is no way to invoke all the plugin executions with a simple command?
I personally expected mvn gwt:compile to invoke everything it needs (so everything that comes earlier in it's lifecycle, including the executions I bound to the prepare-package phase),
or am I missing something obvious?

"mvn package" (or "mvn prepare-package" if you want, but refer to my second rule of thumb)

See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html (in this case specifically the "a build phase is made up of plugin goals" section)

If you'd prefer working with a graph of tasks (like you do in Ant), then again have a look at Gradle.
Reply all
Reply to author
Forward
0 new messages