使用 m2eclipse 设置多个项目的最佳实践
示例场景:我有 2 个项目,“common-project”和“application-project”。 application-project依赖于common-project提供的API。这两个项目还使用了第 3 方 jar(例如番石榴)。
我正在尝试转换为使用 maven 和 m2eclipse,但不清楚最佳方法。目前,我的无 Maven 设置已将第 3 方 jar 添加为公共项目上的库,并标记为“已导出”。这样它们就被应用程序项目继承了,我不必在应用程序项目上显式地将它们添加为库。这两个项目都在积极开发中,所以我不希望先构建一个 common-project 的 jar,然后将其“安装”到我的本地存储库,然后才能使用 application-project 中的新功能。
此类项目布局的推荐方法是什么?我看到以下主题大致涉及该主题: Eclipse 中的项目构建了 Eclipse 中另一个项目使用的 jar
谢谢
Example scenario: I have 2 projects, "common-project" and "application-project". The application-project depends on the API provided by common-project. There are also 3rd party jars (example guava) used by both projects.
I am trying convert to using maven and m2eclipse, but am unclear on the best approach. Currently, my maven-free setup has the 3rd party jars added as libraries on common-project, and marked as "exported". This way they are inherited by application-project, and I don't have to explicitly add them as libraries on application project. Both projects are under active development, so I would prefer not to have to build a jar of common-project first, then "install" that to my local repository before I can use the new features in application-project.
What is the recommended approach for this type of project layout? I see the following thread touches roughly on the topic:
Project in Eclipse that builds a jar used by another project in Eclipse
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将创建 3 个 Maven 项目:一个
parent
聚合模块、一个common-project
模块和一个application-project
模块,具体取决于common -project
并将 guava 声明为parent
模块中的依赖项(以便子项目继承它)。类似这样的:父 pom.xml 看起来像这样:
公共项目的 pom.xml:
应用程序项目的 pom.xml:
这是组织此类项目的 Maven 方式,并且允许触发reactor build 从根项目开始构建一切。
m2eclipse 插件可以解决 Workspace 项目的依赖关系(这实际上是默认行为)。因此,如果您同时导入
application-project
和common-project
,前者将配置为依赖于common- 的源项目
(而不是依赖于jar)。使用此设置时,对common-project
所做的更改将立即可见。这应该可以解决您在 IDE 中的担忧。在 IDE 外部,在顶层项目上运行 Reactor 构建。
I would create 3 maven projects: a
parent
aggregating module, acommon-project
module and anapplication-project
module depending oncommon-project
and declare guava as dependency in theparent
module (so that child project will inherit it). Something like this:Where the parent pom.xml looks like this:
The pom.xml for the common-project:
The pom.xml for the application-project:
This is the Maven way to organize such a project and will allow to trigger a reactor build from the root project to build everything.
The m2eclipse plugin can Resolve dependencies from Workspace projects (this is actually the default behavior). So if you import both
application-project
andcommon-project
, the former would be configured to depend on the sources ofcommon-project
(instead of depending on the jar). Changes made tocommon-project
will be immediately visible when using this setup.This should solve your concern inside the IDE. Outside the IDE, run a reactor build on the top project.
在 POM 的
元素中表达每个项目的依赖关系。然后,m2eclipse 插件会自动从 pom.xml 中选取这些内容,并将它们作为库引用添加到 Eclipse 内的构建路径中。
如果
application-project
依赖于common-project
,那么它也会继承它的依赖关系 - 没有必要再次列出两者之间的公共依赖关系application-project
的 pom.xml。Express the dependencies that each project has in the
<dependencies>
element of the POM.The m2eclipse plugin will then automatically pick these up, from the pom.xml, and add them as library references to the build path within Eclipse.
If
application-project
depends oncommon-project
, then it will inherit it's dependencies as well - it will not be necessary to list the common dependencies between the two a second time in the pom.xml ofapplication-project
.假设你的电脑已经安装了maven,然后下载m2eclipse插件安装它并重新启动eclipse。
请记住,maven 构建的目标是生成可以分发和重用的工件,如果您不想在拥有“通用”的稳定版本之前进行
mvn install
,那也没关系。 project”API,虽然在开发过程中这样做并没有什么错。对于您的情况,您可以执行以下操作之一:
common-project
API 是绝对必要的,并且通常不仅会在application-project
的范围内使用然后将您的项目构建为多模块项目,并将common-project
声明为您的应用程序项目
的模块。 以下是如何执行此操作的示例。common-project
通常是一个共享工件,然后独立构建每个项目,并在其 pom.xml 文件中声明两者的依赖关系,eclipse 应该能够找出两者之间的依赖关系。common-project
的部分实现,将其打包,然后使用在
指定它在文件系统中的位置,这将告诉 Maven 依赖项始终存在,并且不会在任何存储库中查找它;尽管执行application-project
中声明为依赖项。 scope>mvn install
会比这更优雅,但您试图避免这种情况。问候。
Assuming you already have maven installed in your computer, then download the m2eclipse pluging install it and restart eclipse.
Remember the goal of a maven build is to produce and artifact that can be distributed and reused, it's OK if you don't want to make a
mvn install
before having a somewhat stable version of you "common-project" API, although there is nothing wrong in doing it during development.For your case you can do one of the following:
common-project
API is absolutely necessary and will more often than not only be used in the confines of theapplication-project
then build your project as a multi-module project and declarecommon-project
to be a module of yourapplication project
. Here is an example of how to do this.common-project
will be more often than not a shared artifact, then build each project independently having declared the dependencies of both in their pom.xml files eclipse should be able to figure out the dependency between the two.common-project
first, package it, and then declaring as a dependency inapplication-project
with the<scope>system<scope>
specifying where in the file system it is located, this will tell maven that the dependency is always present and it would not look it up in any repository; although doing amvn install
will be more elegant than this you're trying to avoid that.Regards.