有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java GWT CodeServer与maven的增量编译问题以及新的包装gwtapp和gwtlib

我一直在玩弄gwt maven插件的最新变化。最值得注意的是,新包装的gwt应用程序和gwt库

据我所知,如果我有一些代码想在不同的GWT应用程序之间重用,那么GWT lib会打包所有需要的源代码和*。gwt。jar中所有类旁边的xml文件。它就像一个符咒

如果我选择多模块maven reactor构建,一切都会在编译时被检测到,我能够顺利地构建和部署。然而,如果我尝试开发,闪亮的GWT 2.7 SuperDevMode无法检测GWT库项目中的更改,显然是因为它们是从JAR中引用的,而不是从更改它们的实际源目录中引用的

为了说明这一点,我使用了Thomas Broyer的模块化工厂原型

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客户端api”的maven模块,其中包含一个将由mvn gwt客户端使用的类。末端结构如下所示:

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

目标是能够在mvngwt客户端api(例如,当前唯一的类:MvngwtApi.java)中编辑文件,然后在SuperDevMode中重新编译,并在不重新启动CodeServer的情况下立即看到更改

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

PS:我试着用build helper maven插件解决这个问题:

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

然而,这并没有改善情况

非常感谢任何提示/建议/想法


编辑:

我能够使用SuperDevMode增量编译,方法是使用前面提到的build helper maven插件配置,将mvngwt客户端api包从“gwt lib”更改为“jar”,并添加一个“maven源插件”。这样,maven编译和部署的工作方式是相同的,但CodeServer会了解mvngwt客户端api源目录中的更改。尽管如此,问题仍然悬而未决,如何使用新的“gwt库”而不丢失CodeServer增量编译。这里可以看到差异:https://github.com/elnicko/maven-gwt-test/compare/master...working_wihtout_gwt-lib_but_with_jar_packaging


共 (1) 个答案

  1. # 1 楼答案

    您必须在依赖项中使用<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.
    

    也许这些应该在信息级别发出,而不是调试


    顺便说一句,与build helper maven插件不同,您可以只使用<type>java-source</type><classifier>sources</classifier>依赖项,就像对mvngwt-shared模块所做的那样