在 Maven 编译阶段无法执行 gwt:compile

Unable to execute gwt:compile during maven compile phase

我正在使用 Maven 构建 GWT 项目。我已经为 GWT 编译添加了 gwt-maven-plugin,如下所示:

<dependency>
    <groupId>com.google.gwt</groupId>
    <artifactId>gwt-user</artifactId>
    <version>2.5.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.google.gwt</groupId>
    <artifactId>gwt-dev</artifactId>
    <version>2.5.0</version>
    <scope>provided</scope>
</dependency>
<build>
   <plugins>
      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>gwt-maven-plugin</artifactId>
          <version>2.5.0</version>
          <executions>
          <execution>
              <configuration>
                  <module>com.karthik.ui.MainWidgets</module>
              </configuration>
              <goals>
                   <goal>compile</goal>
              </goals>
           </execution>
           </executions>
        </plugin>
    </plugins>
</build>

我已将编译目标包含在执行标签下,希望在编译阶段执行 GWT 编译。但是 GWT 编译仅在包阶段或当我执行 运行 mvn package 命令时执行。
即使 provided 范围,我也收到如下所示的警告设置为 gwt-dev 依赖。

[WARNING] Don't declare gwt-dev as a project dependency. This may introduce complex dependency conflict

1) 为什么在编译阶段不执行 GWT 编译?
2) 我应该为 GWT(gwt-user, gwt-dev) 设置什么范围来克服警告?

[WARNING] Don't declare gwt-dev as a project dependency. This may introduce complex dependency conflict

这是建议,不是要求。不过,添加 gwt-dev 有充分的理由:

  • 如果你写一个生成器
  • 如果你写一个链接器

如果你做这些事情,一定要将 gwt-dev 标记为 <scope>provided</scope>。一般而言,gwt-user 依赖项也应标记为已提供。

如果你不做这些事情,你应该不需要将 gwt-dev 作为项目依赖项包括在内,尽管如果你想混合使用 gwt-maven-plugin 和 gwt 作为插件的依赖项可能会有所帮助版本。

为什么不包含 gwt-dev?除了上述情况之外,没有任何时候您可能需要在该 jar 中引用 classes - 您需要的一切都在 gwt-user 中(或服务器上 运行time 的 gwt-servlet) . gwt-maven-plugin 会自动将 gwt-dev 添加到您的 class 路径,以便编译器可以 运行 正确。


至于"Why GWT compilation is not executed during compile phase?":

你专门配置了gwt-maven-plugin 运行 gwt:compile,但是你忘了告诉它什么时候到运行它,所以它在默认时间 运行 宁它 - 在 prepare-package 期间。相反,您需要在 <execution> 标签中指定 <phase>compile</phase>

但是,compile 阶段可能为时过早 - 如果在您的 .java 文件被编译为 .class 字节码之前发生在 运行,编译器将失败。从生命周期文档 https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html:

考虑另一个时间,例如 process-classes 或更晚的时间

process-classes post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.