簡體   English   中英

將GWT項目轉換為多模塊項目

[英]Transform GWT-Project to Multi-Module Project

我正在嘗試將一個正常工作的GWT項目轉換為幾個Maven模塊。 新結構應如下所示:

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

我的文件看起來像這樣(很多依賴項,我認為我刪除了不必要的內容以使我的問題更加清楚)Project 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>

項目通用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>

Project-War 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]第20行:com.project.errorcodes.ErrorCode類型沒有源代碼。 您忘了繼承必需的模塊嗎? [INFO] [ERROR]提示:檢查模塊的繼承鏈; 它可能未繼承所需的模塊,或者模塊未正確添加其源路徑條目

您的Project-Common不會打包其源以供Project-War使用,因此GWT實際上無法找到ErrorCodes類的源。

您必須使用Project-Common中的maven-source-pluginjar-no-fork目標來打包源,然后使用<classifier>sources</classifier>在Project-War中添加對Project-Common的第二個依賴關系; 或將src/main/java聲明為資源目錄,以將源打包到Project-Common的JAR中。


附帶說明一下,Mojo的GWT Maven插件不適用於多模塊項目。 我建議您切換到net.ltgt.gwt.maven:gwt-maven-plugin ,該net.ltgt.gwt.maven:gwt-maven-plugin是專為多模塊構建而設計的(免責聲明:我是該插件的作者,也是Mojo插件的前維護者) )

找到一個解決方案:

在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>

似乎需要在提供的范圍內與分類器相關。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM