如何使用 gwt-maven-plugin 编译包含在测试源中的 GWT 模块?

How to compile a GWT module contained in the test source with gwt-maven-plugin?

我正在尝试运行 GWT通过插件gwt-maven-plugin用maven编译,但是GWT模块包含在测试源路径中,即:src/test/java。插件抱怨找不到 GWT 模块。

但是,当使用 GWT class DevMode 通过 Eclipse 启动文件使用该模块时,该模块工作正常。 为什么gwt maven插件找不到GWT模块?

该项目包含 2 个 Gwt 模块,1 个 GwtTotalProd 包含在主源中,一个 GwtTotalTest 包含在测试源中。 gwt maven 插件能够构建 GwtTotalProd,但不能构建 GwtTotalTest,为什么(运行 通过 Eclipse 启动文件都可以)? 我尝试在构建 pom 中包含测试源(见下文),但没有成功。

查看 Maven 调试输出(-X 开关),我可以理解它找不到它,因为 GWT SDK 执行包含 src/main/java,但不包含 src/test/java,并且它不包括插件中定义的依赖项。 那么如何让插件在测试源路径中查找呢?

我可以通过创建一个额外的 "test/dev" 项目来做到这一点,该项目在主要源代码中包含 GwtTotalTest(我为其他项目这样做),但在这种情况下,这是不需要的,因为它将是一个空的只有 Gwt 配置文件的项目 ;)... 或者我应该将它绑定到另一个 Maven 阶段?而不是目标 "compile" 我尝试了目标 "test" (测试编译似乎不起作用,maven 说它无法在他的插件中找到目标),但也没有运气.. .

我正在使用插件版本 2.7.0 和配置专家:

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <id>TotalProd</id>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                    <configuration>
                        <module>com.total.GwtTotalProd</module>
                        <mode>htmlunit</mode>
                        <draftCompile>false</draftCompile>
                        <disableClassMetadata>true</disableClassMetadata> 
                        <compileReport>true</compileReport>
                        <warSourceDirectory>${gwt.war}</warSourceDirectory>
                        <webappDirectory>${gwt.output.total}</webappDirectory>
                        <gen>${gwt.output.total}/${gwt.gen}</gen>
                        <extra>${gwt.output.total}/${gwt.extra}</extra>
                        <fragmentCount>8</fragmentCount>
                        <extraJvmArgs>-Xms1G -Xmx1G -Xss1024k -Dgwt.persistentunitcache=false</extraJvmArgs>
                    </configuration>
                </execution>
                <execution>
                    <phase>compile</phase>
                    <id>TotalTest</id>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                    <configuration>
                        <module>com.total.GwtTotalTest</module>
                        <mode>htmlunit</mode>
                        <draftCompile>false</draftCompile>
                        <disableClassMetadata>true</disableClassMetadata> 
                        <compileReport>false</compileReport>
                        <warSourceDirectory>${gwt.war}</warSourceDirectory>
                        <webappDirectory>${gwt.output.total.test}</webappDirectory>
                        <gen>${gwt.output.total.test}/${gwt.gen}</gen>
                        <extra>${gwt.output.total.test}/${gwt.extra}</extra>
                        <fragmentCount>8</fragmentCount>
                        <extraJvmArgs>-Xms1G -Xmx1G -Xss1024k -Dgwt.persistentunitcache=false</extraJvmArgs>
                        <dependencies>
                            <dependency>
                                <groupId>com.company.gwt</groupId>
                                <artifactId>total-gwt</artifactId>
                                <version>${version.gen}</version>
                                <classifier>test-sources</classifier>
                            </dependency>
                            <dependency> 
                                <groupId>com.company.gwt</groupId>
                                <artifactId>total-gwt</artifactId>
                                <version>${version.gen}</version>
                                <type>test-jar</type>
                            </dependency>
                        </dependencies>
                    </configuration>
                </execution>
            </executions>
        </plugin>

插件不提供此功能。正如您所指出的,如果确实如此,它(可能)将是一个 testCompile 目标。

虽然有几种方法可以做到这一点:

  • 如您所述,使用单独的 Maven 模块
  • 在构建期间使用 maven-invoker-plugin 启动 Maven 模块,其源代码包含在模块本身中(而不是反应器构建中的单独模块)
  • 使用 GWTTestCasegetModuleName() returns com.total.GwtTotalTest 你 运行 与 gwt:test productionMode 设置为 true(这样模块将在任何测试方法 运行 之前编译)。