0

我正在尝试将一个工作的单个 GWT 项目转换为几个 Maven 模块。新结构应如下所示:

Project
|- pom.xml
|- Project-Common(only Common-Classes)
|--- pom.xml
|--- Packaging: jar
|- Project-War(includes *gwt.xml)
|--- pom.xml
|--- Packaging: war

我的文件看起来像这样(许多依赖项,我想我删除了不必要的内容以使我的问题更清楚)项目 pom.xml:

<modelVersion>4.0.0</modelVersion>
<artifactId>project</artifactId>
<packaging>pom</packaging>
<name>Project - Modules</name>
<version>1.0.0-SNAPSHOT</version>

<parent>
    <groupId>com.project</groupId>
    <artifactId>project-parent-parent</artifactId>
    <version>2.0.0</version>
    <relativePath />
</parent>
<modules>
    <module>/project-war</module>
    <module>/project-common</module>
</modules>

项目-Common pom.xml:

<modelVersion>4.0.0</modelVersion>
<artifactId>project-common</artifactId>
<packaging>jar</packaging>
<name>Project - Common</name>
<version>1.0.0-SNAPSHOT</version>

<parent>
    <groupId>com.project</groupId>
    <artifactId>project-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath />
</parent>

<build>
    <plugins>
        <plugin>
          <groupId>com.github.koraktor</groupId>
          <artifactId>mavanagaiata</artifactId>
          <executions>
            <execution>
              <id>load-git-branch</id>
              <phase>validate</phase>
              <goals>
                <goal>commit</goal>
              </goals>
              <configuration>
                <dirtyFlag>*</dirtyFlag>
                <gitDir>../../.git</gitDir>
              </configuration>
            </execution>
          </executions>
        </plugin>
     </plugins>
 </build>

项目战争 pom.xml:

<modelVersion>4.0.0</modelVersion>
<artifactId>project-war</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Project - WAR</name>

<parent>
    <groupId>com.project</groupId>
    <artifactId>parent-project</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>   

<dependencies>
    <dependency>
        <groupId>com.project</groupId>
        <artifactId>project-common</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.7.0</version>
            <inherited>true</inherited>
            <configuration>
                <runTarget>/test.html</runTarget>
                <modules>
                    <module>com.project.modules.Test</module>
                </modules>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <id>VerifyRequestFactoryInterfaces</id>
                        <executable>java</executable>
                        <arguments>
                            <argument>-cp</argument>
                            <classpath />
                            <argument>com.google.web.bindery.requestfactory.apt.ValidationTool</argument>
                            <argument>${project.build.outputDirectory}</argument>
                            <argument>com.project.factorys.TestRequestFactory</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>src/main</directory>
                        <includes>
                            <directory>gwt-unitCache/**</directory>
                        </includes>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
        <plugin>
          <groupId>com.github.koraktor</groupId>
          <artifactId>mavanagaiata</artifactId>
          <executions>
            <execution>
              <id>load-git-branch</id>
              <phase>validate</phase>
              <goals>
                <goal>commit</goal>
              </goals>
              <configuration>
                <dirtyFlag>*</dirtyFlag>
                <gitDir>../../.git</gitDir>
              </configuration>
            </execution>
          </executions>
        </plugin>
    </plugins>
</build>

旧项目在我的 Project-War 中,我添加了 Project & Project-Common。在此设置中,项目构建,我得到“新的” Project-War.war 。但是,当我将 ErrorCode.java 从 Project-War 移动到 Project-Common 时,出现以下错误:

[INFO] 跟踪类型“com.project.modules.TestViewImpl”的编译失败路径 [INFO] [错误] '.../project/project-war/src/main/java/com/project/modules/TestViewImpl 中的错误.java' [INFO] [ERROR] Line 20: No source code is available for type com.project.errorcodes.ErrorCode; 你忘了继承一个必需的模块吗?[INFO] [ERROR] 提示:检查模块的继承链;它可能没有继承所需的模块,或者模块可能没有正确添加其源路径条目

4

2 回答 2

0

您的 Project-Common 未将其源打包以供 Project-War 使用,因此 GWT 实际上无法找到ErrorCodes类的源。

您必须在 Project-Common 中使用maven-source-plugin'jar-no-fork目标来打包源代码,然后在 Project-War 中添加对 Project-Common 的第二个依赖项<classifier>sources</classifier>;或将您的资源目录声明src/main/java为资源目录以将源代码打包到 Project-Common 的 JAR 中。


附带说明一下,Mojo 的 GWT Maven 插件并不适合多模块项目。我建议net.ltgt.gwt.maven:gwt-maven-plugin从头开始切换到专为多模块构建而设计的版本(免责声明:我是该插件的作者,也是 Mojo 插件的前维护者)

于 2016-01-22T11:18:32.380 回答
0

找到解决方案:

在 Common-Project 中添加了一个模块

<module>
 <inherits name='com.google.gwt.activity.Activity' />
 <inherits name='com.google.gwt.place.Place' />
 <inherits name="com.google.gwt.user.User" />
 <inherits name='com.google.web.bindery.requestfactory.RequestFactory' />
 <inherits name="com.google.gwt.user.cellview.CellView" />
 <inherits name='com.google.gwt.logging.Logging' />
 <inherits name="com.google.gwt.inject.Inject" />
 <inherits name="com.google.gwt.text.Text" />
 <inherits name="com.google.gwt.i18n.I18N" />

 <inherits name="com.google.gwt.debug.Debug" />

 <source path="shared"/>
</module>

我的任何 ErrorCode.java 都在 Path shared/** 下。

在我添加的 Project-War 模块<inherits name="com.project.Common" />和 Project-War 的 pom.xml 中:

<dependency>
 <groupId>com.project</groupId>
 <artifactId>project-common</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <scope>compile</scope>
</dependency>
<dependency>
 <groupId>com.project</groupId>
 <artifactId>project-common</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <classifier>sources</classifier>
 <scope>provided</scope>
</dependency>

似乎需要在提供的范围内依赖于分类器。

于 2016-01-22T12:16:39.270 回答