【问题标题】:GWT compilation is skipped in maven when module packaging is pom当模块打包为 pom 时,在 maven 中跳过 GWT 编译
【发布时间】:2013-03-22 05:01:30
【问题描述】:

我正在尝试在另一场战争中重用组装好的 gwt 编译。为此,我尝试将当前 maven 模块的包装从 war 更改为 pom。然后我计划使用 maven-assembly-plugin 压缩 gwt 的模块 js 输出,然后在另一个 war 模块中使用它。

我尝试将 pom.xml 中的包装标签从 <packaging>war</packaging> 更改为 <packaging>pom</packaging>Validation sample 。 gwt-maven-plugin 从不进入编译。相反,它会跳过编译!!!!!!

  1. What is happening?
  2. Is this expected?
  3. Is there any workaround?

【问题讨论】:

  • 我不明白你为什么要从war改成pom?您可以在 .war 之后生成 .zip。我不遵循您在第二个模块中想要做的事情
  • 对 pom 的战争。好奇心 :) 我花了一天时间才意识到 gwt 编译被跳过了。
  • 我可以使用战争而不是 zip 和战争(通过在我需要时将内容从战争本身提取到第二个模块中)。假设我想要设置示例的多模块项目,而我不想编译示例总是下载示例编译的 js 并将其推送到我的 Mega Sample 聚合器项目中。
  • 如果我理解得很好,您是说您想在 maven-repo 中发布您的 example1.war,然后在另一个模块(示例)中您想从所有 exampleX.war 中解压缩静态内容并创建一个新的examples.war,对吧?
  • @Manolo 是的。你可以这样形容。

标签: gwt gwt-maven-plugin


【解决方案1】:

要将多个 gwt 编译的模块合并到一个 .war 文件中,使用 maven-dependency-plugin 非常容易

  1. 将所有 gwt 示例打包为习惯 (.war),并安装它们 mvn installmvn deploy(如果您有私有 maven 存储库)。
  2. 创建一个 war 类型的空 maven 模块,没有代码但具有 maven 文件夹结构,您可以在此处放置您需要的任何其他内容,例如全局 src/main/webapp/index.html
  3. 将新模块配置为使用maven-dependency-plugin,如下所示,然后运行mvn package

    <dependency>
        <groupId>my.group</groupId>
        <artifactId>example1</artifactId>
        <version>...</version>
        <type>war</type>
    </dependency>
    ...
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>unpack-gwt-examples</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>unpack-dependencies</goal>
          </goals>
          <configuration>
            <includeGroupIds>my.group</includeGroupIds>
            <includes>**/example1/**</includes>
            <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

最后,与 gwt-maven-plugin 相关,与任何其他 maven 插件一样,选择 pom-packaging 生命周期的适当阶段(打包、安装或部署)就足够了:

  ...
  <packaging>pom</packaging>
  ...
     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        ...
        <configuration>
        ...
        </configuration>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>compile</goal>
                </goals>
            </execution>
        </executions>
      </plugin>

不幸的是,gwt-maven-plugin 明确禁止在打包为 pom 时进行编译,请看line #269 of CompileMojo.java

【讨论】:

  • 谢谢。这个答案是我的 3 点。当 maven 模块打包为“pom”时,我仍然不清楚 gwt-maven-plugin 跳过编译的行为。
  • 你的 gwt-maven-plugin 配置是什么?你使用哪个阶段来执行 gwt:compile 目标?
  • 如果你注意到我只是在验证示例 pom 中更改了包装类型。
  • sgwt-maven-plugin 在打包为 pom 时跳过编译,所以您应该选择不同的打包或打开项目的问题,正确更新我的答案。
  • 这总结了所有三个查询。我现在就去解决这个问题。稍后将报告 CompileMojo 代码...
【解决方案2】:

您可以将可重用模块(您在 cmets 中作为 samples 提及的模块)创建为没有入口点的单独 GWT 项目。将它们打包为jar,并将以下内容添加为resources

  1. 客户端源代码
  2. 最终编译所需的其他资源项(图像、xml 文件等)

类似这样的:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            ...
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/services/**</include>
                <include>**/client/**</include>
                <include>**/public/**</include>
                <include>**/*.gwt.xml</include>
            </includes>
        </resource>
    </resources>
</build>

就是这样,您可以在任何其他 GWT 项目中重复使用它。当您这样做时,您只需在pom.xmlimport 中添加依赖项(到可重用模块)*.gwt.xml

至于 Maven 的行为,它似乎是正确的。 pom packaging 正在经历 packageinstalldeploy 阶段和

默认情况下,编译目标配置为在“准备包”阶段执行,以尽可能晚地运行。

您可以更改插件执行的阶段,但我认为这是有风险的,因为您无法确切知道在 package 阶段您的代码何时会被编译。

【讨论】:

  • 即使没有代码更改,也会在每个使用上下文中重新编译 gwt 模块。我打算避免 gwt 重新编译。
  • 糟糕!我为我的误会道歉。我会相应地编辑我的答案。
猜你喜欢
  • 2018-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 2012-11-29
  • 2019-02-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多