Maven m2eclipse 检测工作区依赖变化并自动安装

发布于 2024-12-02 09:59:57 字数 330 浏览 0 评论 0原文

我发现在 Eclipse 中使用 m2eclipse 时存在一个恼人的问题。

我的工作区包含 2 个项目,一个应用程序 A 和一个库 B。应用程序 A POM 有 B 作为依赖项,一切正常。 (当我构建应用程序时,会找到并使用项目依赖项)

但是,如果我更改项目 B 中的一些代码并且忘记 mvn:install 它,那么当我构建应用程序时,它会使用库的最后构建版本,并且会丢失我的最后的变化。

有没有办法强制 Maven / M2Eclipse 检查依赖项的源代码是否比最后构建的版本更新,并在安装/部署主应用程序时安装它?

或者我的方法可能是错误的,或者是我遗漏了一些明显的东西?

I found an annoying issue working with m2eclipse in Eclipse.

My workspace contains 2 projects, an application A and a library B. The application A POM has B as a dependency and everything works correctly. (The project dependecy is found and used when I build the application)

But if I change some code in project B and I forgot to mvn:install it, when I build the application it uses the last built version of the library and it loses my last changes.

Is there a way to force Maven / M2Eclipse to check if the source code of the dependecy is newer than the last version built, and to install it when installing/ deploying the main application?

Or maybe my approach is wrong or is something obvious that I'm missing?

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

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

发布评论

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

评论(4

末骤雨初歇 2024-12-09 09:59:57

您可以告诉 m2eclipse 使用工作区中的解析依赖项,而不是通过正常的机制。在项目属性(不是工作区属性)中,选择 Maven->Resolve dependency from Workspace items。

项目属性 Maven -> 解决工作空间项目的依赖关系

这意味着当您更改 B 并随后构建 A 时,这些更改应该会被自动拾取。

但是,如果您在 Eclipse 外部构建,则必须执行正常的 mvn install 才能获取正确的依赖项。

You can tell m2eclipse to use resolve dependencies from the workspace rather than through the normal mechanisms. In your project properties (NOT workspace properties), select Maven->Resolve dependencies from Workspace projects.

Project properties Maven -> Resolve dependencies from Workspace projects

This will mean that when you change B and subsequently build A, the changes should be picked up automatically.

If, however, you build outside Eclipse, you'll have to do the normal mvn install to get the correct dependencies.

说不完的你爱 2024-12-09 09:59:57

我不知道有什么方法告诉 maven 首先构建库,然后构建你的项目。您可以将两个 Maven 命令放入一个脚本中并运行该脚本。

或者,您可以将两个项目放入 Maven 父项目中,然后构建父项目。这会导致所有子项目也被构建(因此在您的情况下是库和应用程序)。

I don't know of a way to tell maven to build the library first, then build your project. You could put two maven commands into a script and run the script.

Alternatively, you could put both projects inside a maven parent project, and then build the parent. This causes all child project to be built too (so in your case the library, and the application).

美男兮 2024-12-09 09:59:57

我认为你在这里有几个选择

  1. 如果你可以更改maven项目设置,我建议你使用maven multimodule

  2. 选项二可能会解决您的问题,但仍然涉及手册当您更改依赖项目 B 时停止,在 eclipse 中为您的依赖项目执行此操作

  3. 选择库 B ==>属性==> Maven==>在项目清理后调用的目标下的输入框中:==>输入:install

  4. 要将您在 eclipse 中对项目 B 所做的任何更改部署到 maven 本地/远程存储库,您必须在 eclipse 中运行 Clean build,这会将最新的库 B 部署到 maven 存储库
  5. 另外请确保您的库 B 版本是开发过程中的快照

I think you have couple of options here

  1. If you can change the maven project set up, I would suggest you to use maven multimodule

  2. Option two might solve your problem but still involves a manual stop when you change your dependent project B, Do this on for your dependent project in eclipse

  3. Select Library B ==> Properties ==> Maven ==> in the input box under Goals to invoke after project clean: ==> enter : install

  4. To deploy any change that you made to Project B in eclipse to maven local/remote repo, You have to run Clean build in eclipse, This will deploy the latest Library B to the maven repository
  5. Also make sure your Library B version is a SnapShot during the development
慢慢从新开始 2024-12-09 09:59:57

如果您希望在本地计算机上运行最新的快照,您应该尝试将其设置为直接从 Eclipse 启动。

除了避免您最初发布的问题之外,它还有其他优点。

  • 无需执行中间构建步骤,将为您节省大量时间。
  • 您无需离开 IDE 即可启动和停止服务器。
  • Eclipse 控制台具有系统控制台无法提供的额外功能。
  • 您不必修改启动脚本来附加调试器。

If you are looking to run the latest snapshots on your local machine you should try to set things up to launch directly from Eclipse.

Apart from avoiding the problem you originally posted about, it also has other advantages.

  • It will save you a lot of time by not having to perform intermediate build steps.
  • You can start and stop servers without having to leave your IDE.
  • The Eclipse console has extra features that you don't get from the system console.
  • You don't have to modify your start scripts to attach a debugger.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文