java - GWT CodeServer使用maven和新包装gwt-app和gwt-lib的增量编译问题

标签 java eclipse maven gwt

我一直在研究 gwt-maven-plugin 的最新变化。最值得注意的是新包装 gwt-app 和 gwt-lib。

据我了解,如果我有一些代码想要在不同的 GWT 应用程序之间重用,gwt-lib 会将所有需要的源代码和 *.gwt.xml 文件打包到所有类旁边的 jar 中。它就像一个魅力。

如果我选择多模块 Maven Reactor 构建,所有内容都会在编译时检测到,并且我能够毫无麻烦地成功构建和部署。然而,如果我尝试开发, Shiny 的 GWT 2.7 SuperDevMode 无法检测到 gwt-lib 项目中的更改,显然是因为它们是从 jar 中引用的,而不是从更改它们的实际源目录中引用的。

为了说明这一点,我使用了 Thomas Broyer 的模块化请求工厂原型(prototype)。

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

我输入了以下信息:

Define value for property 'artifactId': : mvngwt
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  com.test: : 
Define value for property 'module':  App: : MvngwtApp
Define value for property 'module-short-name':  mvngwtapp: : 

之后,我创建了一个名为“mvn-gwt-client-api”的附加 Maven 模块,其中包含 mvn-gwt-client 将使用的单个类。最终结构如下所示:

mvngwt/
--mvngwt-client/
--mvngwt-client-api/
--mvngwt-server/
--mvngwt-shared/
--pom.xml

目标是能够编辑 mvngwt-client-api 中的文件(例如当前唯一的类:MvngwtApi.java),然后在 SuperDevMode 中重新编译,并立即看到更改,而无需重新启动 CodeServer。

可以在此处找到该项目的工作副本:https://github.com/elnicko/maven-gwt-test

PS:我尝试使用 build-helper-maven-plugin 解决这个问题:

<profiles>
        <profile>
            <!-- elnicko: add to support CodeServer hot compile for referenced libraries -->
            <id>env-dev</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>dev</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>add-shared-sources-to-classpath</id>
                                <!-- 
                                <phase>process-classes</phase> 
                                <phase>compile</phase> 
                                -->
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>${basedir}/../mvngwt-client-api/src/main/java</source>
                                    </sources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

但这并没有改善情况。

非常感谢任何提示/指针/想法。


编辑:

我可以通过使用前面提到的 build-helper-maven-plugin 配置来使用 SuperDevMode 增量编译,将 mvngwt-client-api 打包从“gwt-lib”更改为“jar”,并添加“maven-源插件”。这样,maven 编译和部署的工作方式是相同的,但 CodeServer 会意识到 mvngwt-client-api 源目录中的更改。尽管如此,问题仍然存在,即如何在不丢失 CodeServer 增量编译的情况下使用新的“gwt-lib”。差异可以在这里看到:https://github.com/elnicko/maven-gwt-test/compare/master...working_wihtout_gwt-lib_but_with_jar_packaging

最佳答案

您必须使用<type>gwt-lib</type>在你的依赖中。

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>mvngwt-client-api</artifactId>
  <version>${project.version}</version>
  <type>gwt-lib</type>
</dependency>

实际上,如果你用 -X 运行 Maven您将在日志中看到:

[DEBUG] Adding sources for com.test:mvngwt-client:gwt-app:1.0-SNAPSHOT
[DEBUG] Ignoring com.test:mvngwt-shared:jar:1.0-SNAPSHOT; neither a java-source, gwt-lib or jar:sources.
[DEBUG] Adding sources for com.test:mvngwt-shared:jar:1.0-SNAPSHOT
[DEBUG] Ignoring com.test:mvngwt-client-api:jar:1.0-SNAPSHOT; neither a java-source, gwt-lib or jar:sources.
[DEBUG] Ignoring com.google.gwt:gwt-user:jar:2.7.0; neither a java-source, gwt-lib or jar:sources.
[DEBUG] Ignoring com.google.gwt:gwt-dev:jar:2.7.0; neither a java-source, gwt-lib or jar:sources.
[DEBUG] Ignoring com.google.gwt:gwt-codeserver:jar:2.7.0; neither a java-source, gwt-lib or jar:sources.

也许这些应该在 INFO 级别而不是 DEBUG 级别发出......


顺便说一句,您可以只使用 <type>java-source</type> 而不是 build-helper-maven-plugin或<classifier>sources</classifier>依赖关系,就像对 mvngwt-shared 所做的那样模块。

关于java - GWT CodeServer使用maven和新包装gwt-app和gwt-lib的增量编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29577407/

相关文章:

java - 使用 Java 写入文件

java - 如何在 eclipse e4 中将值从一个 View 发送到另一 View ?

android - 有没有办法将 Eclipse、1 个库 + 2 个应用程序项目转换为 Android Studio、2 个构建变体

maven - 为 Maven Archetype 插件指定依赖版本

java - 没有 "java.lang.Class<org.springframework.data.repository.Repository<?, ?>>"类型的合格 bean

java - 枚举中的耦合

java - JSP 错误 : According to TLD, 标记形式 :input must be empty, 但不是

java - 使用maven项目用launch4j生成exe

java - 如何使用spring在kafka中创建两个接受不同数据类型的生产者kafka模板,一个是JsonNode,另一个是Avro?

eclipse项目未在本地Maven存储库中导入jar包