将多模块 maven 项目导入 Eclipse (STS 2.5.2) 时遇到问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5219832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trouble importing multi module maven project in to Eclipse (STS 2.5.2)
提问by C0deAttack
I've just spent the last hour looking at threads on Stackoverflow.com , trying to import a Maven project in to Spring ToolSuite 2.5.2.
我刚刚花了最后一个小时查看 Stackoverflow.com 上的线程,尝试将 Maven 项目导入 Spring ToolSuite 2.5.2。
The Maven project has multiple modules, when I use the Import... wizard in STS to import the project All the Modules are listed in the Package Explorer and some of the modules dependencies are not resolved.
Maven项目有多个模块,当我使用STS中的Import...向导导入项目时,所有模块都列在Package Explorer中,部分模块依赖没有解决。
Can any advise on the proper way to import a Multi-Module Maven project in to STS/Eclipse such that all the modules appear under a Parent directory? And so all the modules dependencies are resolved?
能否就将多模块 Maven 项目导入 STS/Eclipse 的正确方法提出建议,以便所有模块都出现在父目录下?那么所有的模块依赖都解决了吗?
The project is in a hierarchy on the file system, I've tried the various Update Dependencies, Project Configuration options but all to no avail. I have an embedded version of Maven installed in the IDE.
该项目位于文件系统的层次结构中,我尝试了各种更新依赖项、项目配置选项,但都无济于事。我在 IDE 中安装了嵌入式版本的 Maven。
Thanks for your time.
谢谢你的时间。
回答by Sean Patrick Floyd
M2Eclipse does a very good job at resolving inter-project dependencies. If it doesn't work, perhaps your project structure has errors. Check that:
M2Eclipse 在解决项目间的依赖关系方面做得非常好。如果它不起作用,则可能是您的项目结构有错误。检查:
- every child project references the correct version of the parent project
- every dependency has the version that corresponds to the current project version in the workspace
- every child project is registered as a
<module>
in the parent pom (profile must be active if the module is defined in a profile).
- 每个子项目都引用了父项目的正确版本
- 每个依赖项都有对应于工作区中当前项目版本的版本
- 每个子项目都
<module>
在父 pom 中注册为 a (如果模块在配置文件中定义,则配置文件必须处于活动状态)。
If these versions don't match, the artifacts referenced will be pulled from the local repository, not the eclipse workspace.
如果这些版本不匹配,则引用的工件将从本地存储库中提取,而不是从 eclipse 工作区中提取。
About common root projects: I don't think it's a good idea to have a common Project, but the Eclipse concept that comes to mind (and that I use for multi-module projects) is a Working Set.
关于共同的根项目:我认为拥有一个共同的Project不是一个好主意,但想到的 Eclipse 概念(以及我用于多模块项目)是一个Working Set。
In the Package Explorer, switch the Top Level Elements
to Working Sets
:
在包资源管理器中,切换Top Level Elements
到Working Sets
:
Now choose Configure Working Sets ...
from the same menu.
现在Configure Working Sets ...
从相同的菜单中选择。
Here's a working set with the maven3 trunk and all submodules as separate projects:
这是一个将 maven3 主干和所有子模块作为单独项目的工作集:
回答by Dmytro
Ugly trick - but sometimes can help:
丑陋的伎俩 - 但有时会有所帮助:
mvn clean eclipse:clean eclipse:eclipse
- Import projects as usual Eclipse project
- enable Maven's Dependency Management
- Perform Update Project Configurationfor all modules
mvn clean eclipse:clean eclipse:eclipse
- 像往常一样导入项目 Eclipse 项目
- 启用Maven的依赖管理
- 为所有模块执行更新项目配置