2016-01-21 54 views
0

我正在嘗試將正在工作的單個GWT項目轉換爲多個Maven模塊。 新的結構應該是這樣的:將GWT項目轉換爲多模塊項目

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> 

項目常見的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.war。 但是當我移動ErrorCode.java從Project-戰爭到項目,共同我得到以下錯誤:

[INFO] Tracing compile failure path for type 'com.project.modules.TestViewImpl' [INFO] [ERROR] Errors in '.../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; did you forget to inherit a required module? [INFO] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

+0

您的常用類是否在您的GWT項目中使用?如果是的話,這個項目也有一個模塊描述符,你是否繼承了你的項目戰爭模塊描述符? –

回答

0

找到了解決辦法:

增加在公共項目

<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下通道共享/ A模塊**。

在Project-戰模塊我加<inherits name="com.project.Common" />並從項目-戰爭的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> 

似乎需要在範圍分類提供的依賴。

0

您的項目,共同的不包其來源是提供給項目戰,所以GWT有效地找不到ErrorCodes類的來源。

您必須使用Project-Common中的maven-source-pluginjar-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(免責聲明:我該插件的作者,魔的插件前維護者)