gwt-maven-plugin not finding sources in a maven module in a GWT maven reactor build

I have the goal of creating a maven reactor build for a modular RequestFactory project. I’m using Thomas Broyer’s maven archetype as suggested by him in GWT Code Server not finding a module in a newly generated project using a maven archetype,

Thanks to his effort, it works immediately out of the box and without any problems whatsoever. It creates three modules (with names ending in client, server, shared).

What bugs me is that three projects have their java sources in the same package. One of the things I tried to do, after the project was up and running, was to refactor the packages of the three maven modules to actually end in their respective names. This works for all but the client project, since the GWT compiler (gwt-maven-plugin) does not seem to look for sources outside of the client project’s own package when building the client package.

Hence, if the shared project has it’s own package that is not a subpackage of the client’s, this will result in GWT not being able to resolve all sources in shared.

My question is, am I missing something obvious, or am I trying to do something that is not recommended at all? Any pointers would be greatly appreciated.

I have been toying around with GWT and maven for a while now, but am still no expert so please bear with me :-). Here is what I did in detail:

Created the project using Thomas Broyer’s archetype (the first time I selected “N” in order to be able to input a module name different than “App” the second time):

mvn archetype:generate 
   -DarchetypeCatalog=https://oss.sonatype.org/content/repositories/snapshots/ 
   -DarchetypeGroupId=net.ltgt.gwt.archetypes 
   -DarchetypeArtifactId=modular-requestfactory 
   -DarchetypeVersion=1.0-SNAPSHOT

Define value for property 'groupId': : com.example
Define value for property 'artifactId': : my-modular-app
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  com.example: : com.example.my.modular.app
Define value for property 'module':  App: : MyModularApp
Define value for property 'module-short-name':  ${module.toLowerCase()}: :
Confirm properties configuration:
groupId: com.example
artifactId: my-modular-app
version: 1.0-SNAPSHOT
package: com.example.my.modular.app
module: MyModularApp
module-short-name: ${module.toLowerCase()}
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: modular-requestfactory:1.0-SNAPSHOT
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.example
[INFO] Parameter: artifactId, Value: my-modular-app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.example.my.modular.app
[INFO] Parameter: packageInPathFormat, Value: com/example/my/modular/app
[INFO] Parameter: package, Value: com.example.my.modular.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: module, Value: MyModularApp
[INFO] Parameter: groupId, Value: com.example
Feb 22, 2015 12:51:56 PM org.apache.velocity.runtime.log.JdkLogChute log
INFO: FileResourceLoader : adding path '.'
[INFO] Parameter: module-short-name, Value: mymodularapp
[INFO] Parameter: artifactId, Value: my-modular-app
[INFO] Parent element not overwritten in /private/tmp/mvn/my-modular-app/my-modular-app-client/pom.xml
[INFO] Parent element not overwritten in /private/tmp/mvn/my-modular-app/my-modular-app-shared/pom.xml
[INFO] Parent element not overwritten in /private/tmp/mvn/my-modular-app/my-modular-app-server/pom.xml
[INFO] project created from Archetype in dir: /private/tmp/mvn/my-modular-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:35 min
[INFO] Finished at: 2015-02-22T12:51:56+01:00
[INFO] Final Memory: 16M/216M
[INFO] ------------------------------------------------------------------------

Executed mvn clean install -Dgwt.draftCompile. Worked like a charm.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] my-modular-app
[INFO] my-modular-app-shared
[INFO] my-modular-app-client
[INFO] my-modular-app-server
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-modular-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-modular-app ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-modular-app ---
[INFO] Installing /private/tmp/mvn/my-modular-app/pom.xml to /Users/nick/.m2/repository/com/example/my-modular-app/1.0-SNAPSHOT/my-modular-app-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-modular-app-shared 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-modular-app-shared ---
[INFO] Deleting /private/tmp/mvn/my-modular-app/my-modular-app-shared/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-modular-app-shared ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-shared/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ my-modular-app-shared ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-modular-app-shared ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-shared/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ my-modular-app-shared ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ my-modular-app-shared ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ my-modular-app-shared ---
[INFO] Building jar: /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/my-modular-app-shared-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ my-modular-app-shared ---
[INFO] Building jar: /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/my-modular-app-shared-1.0-SNAPSHOT-sources.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-modular-app-shared ---
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/my-modular-app-shared-1.0-SNAPSHOT.jar to /Users/nick/.m2/repository/com/example/my-modular-app-shared/1.0-SNAPSHOT/my-modular-app-shared-1.0-SNAPSHOT.jar
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-shared/pom.xml to /Users/nick/.m2/repository/com/example/my-modular-app-shared/1.0-SNAPSHOT/my-modular-app-shared-1.0-SNAPSHOT.pom
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-shared/target/my-modular-app-shared-1.0-SNAPSHOT-sources.jar to /Users/nick/.m2/repository/com/example/my-modular-app-shared/1.0-SNAPSHOT/my-modular-app-shared-1.0-SNAPSHOT-sources.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-modular-app-client 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-modular-app-client ---
[INFO] Deleting /private/tmp/mvn/my-modular-app/my-modular-app-client/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-modular-app-client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-client/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ my-modular-app-client ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /private/tmp/mvn/my-modular-app/my-modular-app-client/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-modular-app-client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-client/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ my-modular-app-client ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ my-modular-app-client ---
[INFO] No tests to run.
[INFO]
[INFO] --- gwt-maven-plugin:2.7.0:compile (gwt-compile) @ my-modular-app-client ---
[INFO] Compiling module com.example.my.modular.app.MyModularApp
[INFO]    Compiling 3 permutations
[INFO]       Compiling permutation 0...
[INFO]       Process output
[INFO]          Compiling
[INFO]             Compiling permutation 1...
[INFO]       Process output
[INFO]          Compiling
[INFO]             Compiling permutation 2...
[INFO]    Compile of permutations succeeded
[INFO]    Compilation succeeded -- 8.061s
[INFO] Linking into /private/tmp/mvn/my-modular-app/my-modular-app-client/target/my-modular-app-client-1.0-SNAPSHOT/mymodularapp
[INFO]    Link succeeded
[INFO]    Linking succeeded -- 0.331s
[INFO]
[INFO] --- maven-war-plugin:2.5:war (default-war) @ my-modular-app-client ---
[INFO] Packaging webapp
[INFO] Assembling webapp [my-modular-app-client] in [/private/tmp/mvn/my-modular-app/my-modular-app-client/target/my-modular-app-client-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/private/tmp/mvn/my-modular-app/my-modular-app-client/src/main/webapp]
[INFO] Webapp assembled in [29 msecs]
[INFO] Building war: /private/tmp/mvn/my-modular-app/my-modular-app-client/target/my-modular-app-client-1.0-SNAPSHOT.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-modular-app-client ---
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-client/target/my-modular-app-client-1.0-SNAPSHOT.war to /Users/nick/.m2/repository/com/example/my-modular-app-client/1.0-SNAPSHOT/my-modular-app-client-1.0-SNAPSHOT.war
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-client/pom.xml to /Users/nick/.m2/repository/com/example/my-modular-app-client/1.0-SNAPSHOT/my-modular-app-client-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-modular-app-server 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-modular-app-server ---
[INFO] Deleting /private/tmp/mvn/my-modular-app/my-modular-app-server/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-modular-app-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-server/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ my-modular-app-server ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /private/tmp/mvn/my-modular-app/my-modular-app-server/target/classes
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:exec (requestfactory-validation-tool) @ my-modular-app-server ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-modular-app-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/mvn/my-modular-app/my-modular-app-server/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ my-modular-app-server ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ my-modular-app-server ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.5:war (default-war) @ my-modular-app-server ---
[INFO] Packaging webapp
[INFO] Assembling webapp [my-modular-app-server] in [/private/tmp/mvn/my-modular-app/my-modular-app-server/target/my-modular-app-server-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/private/tmp/mvn/my-modular-app/my-modular-app-server/src/main/webapp]
[INFO] Processing overlay [ id com.example:my-modular-app-client]
[INFO] Webapp assembled in [50 msecs]
[INFO] Building war: /private/tmp/mvn/my-modular-app/my-modular-app-server/target/my-modular-app-server-1.0-SNAPSHOT.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-modular-app-server ---
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-server/target/my-modular-app-server-1.0-SNAPSHOT.war to /Users/nick/.m2/repository/com/example/my-modular-app-server/1.0-SNAPSHOT/my-modular-app-server-1.0-SNAPSHOT.war
[INFO] Installing /private/tmp/mvn/my-modular-app/my-modular-app-server/pom.xml to /Users/nick/.m2/repository/com/example/my-modular-app-server/1.0-SNAPSHOT/my-modular-app-server-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] my-modular-app ..................................... SUCCESS [  0.185 s]
[INFO] my-modular-app-shared .............................. SUCCESS [  1.014 s]
[INFO] my-modular-app-client .............................. SUCCESS [ 10.829 s]
[INFO] my-modular-app-server .............................. SUCCESS [  1.170 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.341 s
[INFO] Finished at: 2015-02-22T12:55:14+01:00
[INFO] Final Memory: 27M/257M
[INFO] ------------------------------------------------------------------------

Aftwerwards, I refactored the project structure so that each of the client, server, shared has it’s own subpackage.

  1. (check) Refactor project my-modular-app-shared:

    • Rename package com.example.my.modular.app -> com.example.my.modular.app.shared
    • Replace server’s pom.xml reference from com.example.my.modular.app.MyModularAppFactory -> com.example.my.modular.app.shared.MyModularAppFactory
    • Execute mvn clean install -Dgwt.draftCompile with success.
  2. (check) Refactor project my-modular-app-server:

    • Rename package com.example.my.modular.app -> com.example.my.modular.app.server
    • Update GreetingResponseProxy’s @ProxyForName(“com.example.my.modular.app.GreetingResponse”) -> @ProxyForName(“com.example.my.modular.app.server.GreetingResponse”)
    • Update GreetingContext’s @ServiceName(“com.example.my.modular.app.GreetingService”) -> @ServiceName(“com.example.my.modular.app.server.GreetingService”)
    • Execute mvn clean install -Dgwt.draftCompile with success.
  3. (fail) Refactor project my-modular-app-client:

    • Rename package com.example.my.modular.app -> com.example.my.modular.app.client
    • Update client’s MyModuleApp.gwt.xml com.example.my.modular.app.MyModularApp -> com.example.my.modular.app.client.MyModularApp
    • Update client pom.xml’s gwt-maven-plugin module entry com.example.my.modular.app.MyModularApp -> com.example.my.modular.app.client.MyModularApp
[INFO] Compiling module com.example.my.modular.app.client.MyModularApp
[INFO]    Tracing compile failure path for type 'com.example.my.modular.app.client.MyModularApp'
[INFO]       [ERROR] Errors in 'file:/private/tmp/mvn/my-modular-app/my-modular-app-client/src/main/java/com/example/my/modular/app/client/MyModularApp.java'
[INFO]          [ERROR] Line 41: No source code is available for type com.example.my.modular.app.shared.MyModularAppFactory; did you forget to inherit a required module?
[INFO]          [ERROR] Line 135: No source code is available for type com.example.my.modular.app.shared.GreetingResponseProxy; did you forget to inherit a required module?
[INFO]          [ERROR] Line 125: No source code is available for type com.example.my.modular.app.shared.FieldVerifier; did you forget to inherit a required module?
[INFO]    Finding entry point classes
[INFO]       Tracing compile failure path for type 'com.example.my.modular.app.client.MyModularApp'
[INFO]          [ERROR] Errors in 'file:/private/tmp/mvn/my-modular-app/my-modular-app-client/src/main/java/com/example/my/modular/app/client/MyModularApp.java'
[INFO]             [ERROR] Line 41: No source code is available for type com.example.my.modular.app.shared.MyModularAppFactory; did you forget to inherit a required module?
[INFO]             [ERROR] Line 135: No source code is available for type com.example.my.modular.app.shared.GreetingResponseProxy; did you forget to inherit a required module?
[INFO]             [ERROR] Line 125: No source code is available for type com.example.my.modular.app.shared.FieldVerifier; did you forget to inherit a required module?
[INFO]       [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] my-modular-app ..................................... SUCCESS [  0.180 s]
[INFO] my-modular-app-shared .............................. SUCCESS [  0.999 s]
[INFO] my-modular-app-client .............................. FAILURE [  5.156 s]
[INFO] my-modular-app-server .............................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.473 s

There is nothing else in the pom.xml and source files that appears in need to be changed. All Java compilations work out perfectly. However, the end result is a fail, since the GWT compiler (gwt-maven-plugin) does not seem to look for sources outside of the client project’s own package when building the client package. Hence, if the shared project has it’s own subpackage that is not a subpackage of the client’s this will result in gwt-maven-plugin not being able to resolve any sources in shared.

So anything that is under shared is not found by the GWT compiler. Interestingly, if I rename the package in my-modular-app-shared to com.example.my.modular.app.client instead of com.example.my.modular.app.shared and update the references, everything works as a charm.

It seems to me that the problem is that gwt-maven-plugin is confined to the package of the client and all other referenced projects ought to have all GWT relevant sources in subpackages of the client package. The question is, how can I tell the GWT compiler to look in a different package when traversing different maven modules?

Any help/pointers greatly appreciated, and thanks in advance!

PS: I managed to create a workaround by adding the following GWT module in the client project (package com.example.my.modular.app) and inheriting it in the MyModularApp.gwt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
  "-//Google Inc.//DTD Google Web Toolkit 1.6.4//EN"
  "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd">
<module>
  <source path="shared"/>
</module>

So to rephrase the question: there an automatic way of achieving this instead of having the need to declare artificial modules?

Answer

This is just how GWT works, the compiler only sees classes from the source path which is a subset of the classpath.

Generally, people put their gwt.xml in the com.example.my.modular.app package and add client and shared subpackages to the source path:

<source path="client"/>
<source path="shared"/>

Leave a Reply

Your email address will not be published. Required fields are marked *