gwt-maven-plugin 在 GWT maven 反应器构建中的 maven 模块中找不到源代码

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

我的目标是为模块化 RequestFactory 项目创建一个 Maven 反应器构建。我正在使用 Thomas Broyer 在

中建议的 Maven 原型

多亏了他的努力,它开箱即用,没有任何问题。它创建三个模块(名称以客户端、服务器、共享结尾)。

让我烦恼的是三个项目在同一个包中有它们的 java 源代码。在项目启动 运行 之后,我尝试做的一件事是 重构三个 Maven 模块的包 以实际 结束他们各自的名字。这适用于除客户端项目之外的所有项目,因为 GWT 编译器 (gwt-maven-plugin) 在构建客户端包时似乎不会在客户端项目自己的包之外寻找源代码。

因此,如果共享项目有自己的包而不是客户端的子包,这将导致 GWT 无法解析共享中的所有源。

我的问题是,我是否遗漏了一些明显的东西,或者我是否正在尝试做一些根本不推荐的事情?任何指针将不胜感激。

我已经研究 GWT 和 maven 一段时间了,但我仍然不是专家,所以请多多包涵 :-)。以下是我的详细操作:

使用 Thomas Broyer 的原型创建项目(我第一次选择 "N" 以便能够输入不同于 "App" 的模块名称第二次):

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] ------------------------------------------------------------------------

执行了 mvn clean install -Dgwt.draftCompile。工作得很好。

[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] ------------------------------------------------------------------------

之后,我重构了项目结构,使每个客户端、服务器、共享都有自己的子包。

  1. (check) 重构项目 my-modular-app-shared:

    • 重命名包 com.example.my.modular.app -> com.example.my.modular.app.shared
    • 从 com.example.my.modular.app.MyModularAppFactory -> com.example.my.modular.app.shared.MyModularAppFactory
    • 替换服务器的 pom.xml 引用
    • 执行 mvn clean install -Dgwt.draftCompile 成功。
  2. (check) 重构项目 my-modular-app-server:

    • 重命名包 com.example.my.modular.app -> com.example.my.modular.app.server
    • 更新 GreetingResponseProxy 的 @ProxyForName("com.example.my.modular.app.GreetingResponse") -> @ProxyForName("com.example.my.modular.app.server.GreetingResponse")
    • 更新 GreetingContext 的 @ServiceName("com.example.my.modular.app.GreetingService") -> @ServiceName("com.example.my.modular.app.server.GreetingService")
    • 执行 mvn clean install -Dgwt.draftCompile 成功。
  3. (fail) 重构项目 my-modular-app-client:

    • 重命名包 com.example.my.modular.app -> com.example.my.modular.app.client
    • 更新客户端的 MyModuleApp.gwt.xml com.example.my.modular.app.MyModularApp -> com.example.my.modular.app.client.MyModularApp
    • 更新客户端 pom.xml 的 gwt-maven-plugin 模块条目 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

pom.xml 中没有其他内容,需要更改出现的源文件。所有 Java 编译都完美运行。然而,最终结果是失败的,因为 GWT 编译器 (gwt-maven-plugin) 在构建客户端包时似乎不会在客户端项目自己的包之外寻找源代码。因此,如果共享项目有自己的子包,而不是客户端的子包,这将导致 gwt-maven-plugin 无法解析 shared.[=15 中的任何源=]

因此 GWT 编译器找不到共享下的任何内容。有趣的是,如果我将 my-modular-app-shared 中的包重命名为 com.example.my.modular.app.client 而不是 com.example.my.modular.app.shared 并更新引用,一切都会变得很有魅力。

在我看来,问题在于 gwt-maven-plugin 仅限于客户端包,所有其他引用的项目都应该在客户端包的子包中包含所有 GWT 相关源。问题是,在遍历不同的 maven 模块时,如何告诉 GWT 编译器查看不同的包?

任何 help/pointers 非常感谢,并提前致谢!

PS:我设法通过在客户端项目(包 com.example.my.modular.app)中添加以下 GWT 模块并在 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>

所以换个说法:有一种自动的方式来实现这个而不需要声明人工模块?

这就是 GWT 的工作方式,编译器只能从 源路径 中看到 类,它是类路径的一个子集。

通常,人们将他们的 gwt.xml 放在 com.example.my.modular.app 包中,并将客户端和共享子包添加到源路径:

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