[英]Transform GWT-Project to Multi-Module Project
I am trying to transform a working single GWT-Project into several Maven-Modules. 我正在尝试将一个正常工作的GWT项目转换为几个Maven模块。 New structure should look like this:
新结构应如下所示:
Project
|- pom.xml
|- Project-Common(only Common-Classes)
|--- pom.xml
|--- Packaging: jar
|- Project-War(includes *gwt.xml)
|--- pom.xml
|--- Packaging: war
My files look like this(many dependencies, I think i removed the unnecessary to make my problem more clear) Project pom.xml: 我的文件看起来像这样(很多依赖项,我认为我删除了不必要的内容以使我的问题更加清楚)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>
Project-Common pom.xml: 项目通用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: 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>
The old Project was in my Project-War and I added Project & Project-Common. 旧项目位于我的Project War中,我添加了Project&Project-Common。 In this setup the Project builds and I get the "new" Project-War.war .
在此设置中,将构建项目,然后得到“新” Project-War.war。 But when I move a ErrorCode.java from Project-War to Project-Common I get the following Error:
但是,当我将ErrorCode.java从Project-War移到Project-Common时,出现以下错误:
[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;
[INFO]跟踪类型'com.project.modules.TestViewImpl'的编译失败路径[INFO] [错误]'... / project / project-war / src / main / java / com / project / modules / TestViewImpl中的错误.java'[INFO] [ERROR]第20行:com.project.errorcodes.ErrorCode类型没有源代码。 did you forget to inherit a required module?
您忘了继承必需的模块吗? [INFO] [ERROR] Hint: Check the inheritance chain from your module;
[INFO] [ERROR]提示:检查模块的继承链; it may not be inheriting a required module or a module may not be adding its source path entries properly
它可能未继承所需的模块,或者模块未正确添加其源路径条目
Your Project-Common doesn't package its sources to be available to the Project-War, so GWT effectively can't find the source for ErrorCodes
class. 您的Project-Common不会打包其源以供Project-War使用,因此GWT实际上无法找到
ErrorCodes
类的源。
You have to either use the maven-source-plugin
's jar-no-fork
goal in Project-Common to package sources, and then add a second dependency on Project-Common in Project-War with <classifier>sources</classifier>
; 您必须使用Project-Common中的
maven-source-plugin
的jar-no-fork
目标来打包源,然后使用<classifier>sources</classifier>
在Project-War中添加对Project-Common的第二个依赖关系; or declare your src/main/java
as a resource directory to package sources into the Project-Common's JAR. 或将
src/main/java
声明为资源目录,以将源打包到Project-Common的JAR中。
As a side note, Mojo's Maven Plugin for GWT isn't a great fit for multi-module projects. 附带说明一下,Mojo的GWT Maven插件不适用于多模块项目。 I'd advise switching to the
net.ltgt.gwt.maven:gwt-maven-plugin
which was designed for multi-module builds from the ground up (disclaimer: I'm the author of that plugin, and former maintainer of Mojo's plugin) 我建议您切换到
net.ltgt.gwt.maven:gwt-maven-plugin
,该net.ltgt.gwt.maven:gwt-maven-plugin
是专为多模块构建而设计的(免责声明:我是该插件的作者,也是Mojo插件的前维护者) )
Found a Solution: 找到一个解决方案:
Added a Module in Common-Project 在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>
any my ErrorCode.java is under Path shared/** . 我的任何ErrorCode.java都在path shared / **下。
In Project-War Modules I added <inherits name="com.project.Common" />
and in pom.xml from Project-War: 在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>
Seems to need dependency with classifier in scope provided. 似乎需要在提供的范围内与分类器相关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.