Maven m2eclipse 检测工作区依赖变化并自动安装
我发现在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以告诉 m2eclipse 使用工作区中的解析依赖项,而不是通过正常的机制。在项目属性(不是工作区属性)中,选择 Maven->Resolve dependency from Workspace items。
这意味着当您更改 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.
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.
我不知道有什么方法告诉 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).
我认为你在这里有几个选择
如果你可以更改maven项目设置,我建议你使用maven multimodule
选项二可能会解决您的问题,但仍然涉及手册当您更改依赖项目 B 时停止,在 eclipse 中为您的依赖项目执行此操作
选择库 B ==>属性==> Maven==>在项目清理后调用的目标下的输入框中:==>输入:install
I think you have couple of options here
If you can change the maven project set up, I would suggest you to use maven multimodule
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
Select Library B ==> Properties ==> Maven ==> in the input box under Goals to invoke after project clean: ==> enter : install
如果您希望在本地计算机上运行最新的快照,您应该尝试将其设置为直接从 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.