如何更新 gwt-maven-plugin 原型?

How to update gwt-maven-plugin Archetype?

我想用 Eclipse 创建 maven 管理的 gwt 项目 IDE。

我正在使用 GWT 2.7。但是当我从 File > New > Maven Project 创建一个项目并选择 gwt 作为 Archetype 时,请找到下面的图片 -

版本 是 2.1.0-1,生成的 pom.xml 是 gwt 版本 2.1。我该如何更新这个 org.codehaus.mojo Archetype ?或者我可以设置为使用我的 gwt 版本生成吗?

编辑: 生成的 pom.xml 在下方,但我使用的是 gwt 2.7

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <!-- POM file generated with GWT webAppCreator -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.my.test</groupId>
  <artifactId>TestingGWT</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>GWT Maven Archetype</name>

  <properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.1.0</gwtVersion>
    <!-- GWT needs at least java 1.5 -->
    <maven.compiler.source>1.5</maven.compiler.source>
    <maven.compiler.target>1.5</maven.compiler.target>
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>2.1.0</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>2.1.0</version>
      <scope>provided</scope>
    </dependency>  
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <!-- Generate compiled stuff in the folder used for developing mode -->
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

    <plugins>

      <!-- GWT Maven Plugin -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.1.0-1</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test</goal>
              <goal>i18n</goal>
              <goal>generateAsync</goal>
            </goals>
          </execution>
        </executions>
        <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
          documentation at codehaus.org -->
        <configuration>
          <runTarget>testingGWT.html</runTarget>
          <hostedWebapp>${webappDirectory}</hostedWebapp>
          <i18nMessagesBundle>com.my.test.TestingGWT.client.Messages</i18nMessagesBundle>
        </configuration>
      </plugin>

      <!-- Copy static web files before executing gwt:run -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>exploded</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <webappDirectory>${webappDirectory}</webappDirectory>
        </configuration>
      </plugin>

    </plugins>
  </build>

</project>

PS : 请不要建议生成后编辑 pom.xml 文件。

您的 Eclipse 中的原型目录似乎已过时。我不知道如何更新它(我什至不知道 Maven 如何在 Eclipse 之外进行更新),但一个简单的解决方法是使用 Add Archetype… 按钮添加 org.codehaus.mojo:gwt-maven-plugin:2.7.0.


也就是说,尽管 2.7.0 原型比 2.1.0 原型好得多,但我不建议使用它,除非是小型一次性实验或错误重现案例。
对于您希望在 medium/long 期限内维护和发展的任何项目,我强烈建议您为客户端和服务器端代码使用单独的 Maven 模块。我为该多模块设置构建了原型:https://github.com/tbroyer/gwt-maven-archetypes; see announcement here。另请注意,他们不使用 org.codehaus.mojo 插件。