Trouble importing multi module maven project in to Eclipse (STS 2.5.2)
Asked Answered
C

2

4

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.

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.

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?

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.

Thanks for your time.

Chancellorship answered 7/3, 2011 at 12:40 Comment(0)
A
9

M2Eclipse does a very good job at resolving inter-project dependencies. If it doesn't work, perhaps your project structure has errors. Check that:

  • 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).

If these versions don't match, the artifacts referenced will be pulled from the local repository, not the eclipse workspace.


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.

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.

Here's a working set with the maven3 trunk and all submodules as separate projects:

multi module working set

Adige answered 7/3, 2011 at 13:1 Comment(3)
M2Eclipse is installed by default in STS, should have mentioned that sorry. As for possible errors, I've been trough the pom.xml files in the modules and they all seem to be fine.Chancellorship
@Chancellorship I know, sorry I was unclear. I didn't mean for you to install m2eclipse, but to look for bad versions. This is a knowm issue in m2eclipse if the versions don't matchAdige
I don't know how but the dependencies have resolved themselves after doing "mvn clean package" on the command line and then "Importing an existing Maven project" in to STS. Still not sure how I can make all the modules appear under 1 common root project directory though??Chancellorship
C
4

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 Configuration for all modules
Confirm answered 9/3, 2011 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.