GWT 在编译器的类路径上获取继承模块

发布于 2024-11-08 20:50:49 字数 164 浏览 0 评论 0原文

我有一个包含多个 gwt 模块的项目,其中一个是库模块,没有其他模块继承的入口点。所有模块都包含在使用 maven 和 gwt-maven-plugin 构建的单个项目中。不幸的是,构建项目失败,因为 gwt:compile 在编译继承它的主模块时正在类路径上查找继承的模块。如何在类路径上获取库模块以编译主模块?

I have a project with multiple gwt modules, one of which is a library module without an entry point from which the other modules inherit. All the modules are contained in a single project built using maven and the gwt-maven-plugin. Unfortunately, building the project fails because gwt:compile is looking for the inherited module on the classpath when it compiles the main modules that inherit it. How do I get the library module on the classpath for the compilation of the main modules?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

拥抱我好吗 2024-11-15 20:50:49

你需要做一些创造性的“Maven-ing”,因为我刚刚创造了这个术语来描述它。 (实际上,它可能根本没有创意,但我自己也是一个 Maven 新手,所以它也困扰了我一段时间)。

从某种意义上说,您是对的,当 GWT 编译器尝试编译您的“主”模块时,它正在类路径上寻找继承模块的源代码。为了实现这一点,您需要向主模块的 pom 添加对库模块源的依赖关系(仅限于编译阶段)。

像这样:

...
<artifactId>main-module</artifactId>
...
<dependency>
  <groupId>library-group</groupId>
  <artifactId>library-artifact</artifactId>
  <type>jar</type>
  <version>0.1-SNAPSHOT</version>
  <classifier>sources</classifier>
  <scope>compile</scope>
</dependency>
...

现在,您获取这些来源的来源可能有所不同。如果您只是尝试从 IDE(例如 Eclipse)执行此操作,这可能就足够了,因为 m2eclipse 插件足够智能,可以知道从哪里获取这些源(如果库模块也在您的工作区中)。如果这是您的实际构建过程,那么您将需要修改库模块的 pom 以生成 -sources 工件以及标准“库工件”。所以你最终会得到两者:

library-artifact-0.1-SNAPSHOT.jar

并且

library-artifact-0.1-SNAPSHOT-sources.jar

希望更清楚 gwt-maven-plugin 从那时起是如何进行的。

差点忘了,我在这里回答的另一个问题可能也有一些用处: GWT 项目结构

You're going to need to do some creative "Maven-ing," as I just made up the term to describe it. (In reality it probably isn't creative at all, but I'm a bit of a Maven newbie myself, so it stumped me for a while too).

You're right in a sense, the GWT comipler is looking for the inherited module's source on the classpath when it tries to compile your "main" module. To achieve this, you will need to add a dependency, to the main module's pom, on the library module's sources (strictly for the compile phase).

Something like this:

...
<artifactId>main-module</artifactId>
...
<dependency>
  <groupId>library-group</groupId>
  <artifactId>library-artifact</artifactId>
  <type>jar</type>
  <version>0.1-SNAPSHOT</version>
  <classifier>sources</classifier>
  <scope>compile</scope>
</dependency>
...

Now, where you get those sources from can differ. If you're just trying to do this from an IDE, like Eclipse, this is probably enough because the m2eclipse plugin is smart enough to know where to get those sources (if the library-module is also in your workspace). If this is your actual build process, then you will need to modify the library-module's pom to produce the -sources artifact along with the standard "library-artifact." So you'll end up with both:

library-artifact-0.1-SNAPSHOT.jar

and

library-artifact-0.1-SNAPSHOT-sources.jar

Hopefully it's more clear how the gwt-maven-plugin proceeds from that point.

Almost forgot, the one other question I've answered here might be of some use as well: GWT Project Structure.

对岸观火 2024-11-15 20:50:49

好的,我可以通过在项目的 pom 文件的 gwt-maven-plugin 配置中显式列出我的 GWT 模块来解决这个问题。通过这样做,我能够强制执行 GWT 编译的顺序,确保共享模块首先被编译,并且可供在编译过程中继承它的其他模块使用。

以下是配置示例:

<configuration>
  <modules>
    <module>com.foo.gwt.shared.Shared</module>
    <module>com.foo.feature.one.gwt.One</module>
    <module>com.foo.feature.two.gwt.Two</module>
  </modules>
</configuration>

感谢 Jason482 的所有帮助。

Ok, I was able to solve this by explicitly listing my GWT modules in the project's pom file's gwt-maven-plugin configuration. By doing this, I was able to enforce the order of GWT compilation, ensuring that the shared module was compiled first and available to the other modules that inherit from it during their compilations.

Here is an example of the config:

<configuration>
  <modules>
    <module>com.foo.gwt.shared.Shared</module>
    <module>com.foo.feature.one.gwt.One</module>
    <module>com.foo.feature.two.gwt.Two</module>
  </modules>
</configuration>

Thanks to Jason482 for all the help.

圈圈圆圆圈圈 2024-11-15 20:50:49

我更愿意对上面的答案发表评论,但我没有足够的代表来做这件事。所以我在这里发布我的发现。

Jason482的回答对我有用。添加:

sources
compile

到反应器 pom 内的每个子模块依赖项,解决了我的问题。

mreynolds 采用的解决方案是将 GWT 模块引用添加到主 pom 文件的 gwt-maven-plugin 配置中,似乎仅当您的 GWT 子模块中有其他入口点时才需要。我没有,所以这一步对我来说没有必要。

I would have preferred to comment on the answer above but I do not have enough rep to do it. So I am posting my findings here.

Jason482's answer worked for me. Adding:

<classifier>sources</classifier>
<scope>compile</scope>

to each of my sub-modules dependencies, inside the reactor pom, solved my issue.

The solution that mreynolds went with, adding GWT module references to the main pom file's gwt-maven-plugin configuration, seems to be necessary ONLY if you have other entry points in your GWT submodules. I did not, so that step was not necessary for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文