【问题标题】:gwt-maven-plugin runs permutations even when there are no changes即使没有更改,gwt-maven-plugin 也会运行排列
【发布时间】:2014-01-20 04:36:26
【问题描述】:

我们在我们的产品中使用 GWT 和 mojo gwt-maven-plugin 2.4 来编译 GWT 代码。 但是我们观察到,当我们运行 mvn install 时,即使没有对 GWT 代码进行任何代码更改,gwt maven 插件也会运行排列。

在这个问题上苦苦挣扎了很长一段时间后,我们能够使用 2 个 maven 项目通过简单的设置来重现它:

  • 第一个项目(MyGwtMavenSampleSource):包含 GWT 代码以及 gwt 模块 xml 文件
  • 第二个项目 (MavenBuilderMod):包含 MyGwtMavenSampleSource 作为 maven 依赖项并将构建战争 文件。

以下是这两个项目的 pom:

第一个项目:MyGwtMavenSampleSource

<?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>GWTMavenPlugin</groupId>
  <artifactId>MyGwtMavenSampleSource</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>GWT Maven Archetype</name>

  <properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.4.0</gwtVersion>
    <!-- GWT needs at least java 1.5 -->
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>${gwtVersion}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>${gwtVersion}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
      <classifier>sources</classifier>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

第二个项目:MavenBuilderMod

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>GWTMavenPlugin</groupId>
  <artifactId>MavenBuilderMod</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.4.0</gwtVersion>
    <!-- GWT needs at least java 1.5 -->
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>${gwtVersion}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>${gwtVersion}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
      <classifier>sources</classifier>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>GWTMavenPlugin</groupId>
      <artifactId>MyGwtMavenSampleSource</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
    <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <executions>
              <execution>
                <id>src-dependencies</id>
                <phase>package</phase>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                  <classifier>sources</classifier>
                  <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
                  <outputDirectory>${project.build.directory}/sources</outputDirectory>
                </configuration>
              </execution>
            </executions>
        </plugin>
      <!-- GWT Maven Plugin -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.4.0</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
        <!-- Plugin configuration. There are many available options, see 
          gwt-maven-plugin documentation at codehaus.org -->
        <configuration>
          <runTarget>MyGwtMavenSampleSource.html</runTarget>
          <hostedWebapp>${webappDirectory}</hostedWebapp>
          <modules>
            <module>com.ca.gwt.maven.sample.MyGwtMavenSampleSource</module>
        </modules>
        </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>
          </execution>
        </executions>
        <configuration>
          <webappDirectory>${webappDirectory}</webappDirectory>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

所以,问题是,我们如何才能让 gwt-maven-plugin / 编译器在这种设置中仅在代码更改时运行排列。


注意:如果将 gwt 模块 xml 文件放置在包含 gwt-maven-plugin 的同一 maven 模块中,这将按预期工作(即仅在更改代码时运行排列)

【问题讨论】:

    标签: java eclipse maven gwt plugins


    【解决方案1】:

    根本问题是 Maven 对增量构建的支持中断,并且可能在 gwt-maven-plugin 中破坏了增量构建支持(特别是如果您仍在使用超过 2 年的版本!)。

    gwt-maven-plugin 以某种方式看到 gwt.xml 文件已更改(跟踪您的第一个模块的构建,理想情况下,如果没有任何更改,它应该真的是空操作;重新复制资源和/或重建JAR 可能足以向下触发问题),尤其是比它生成的 nocache.js 文件更新。

    我认为更好的设置是在第一个模块中运行 gwt-maven-plugin 并将所有内容打包在 ZIP 或 WAR 中,然后您可以将其用作 WAR 覆盖。不幸的是,这让 DevMode 的运行变得有些困难,但 it's workable.

    【讨论】:

      猜你喜欢
      • 2016-06-18
      • 2013-02-12
      • 2013-09-06
      • 2022-01-21
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      相关资源
      最近更新 更多