Eclipse + Maven + Git + Multi-Module projects = Unhappiness

11,839

Solution 1

A standard Maven multi-module structure as a single git repo works perfectly fine for me in Eclipse Indigo with M2e and the git plugin that shows up in that environment. You can't ask Eclipse to do your fetching for you, but once you've pulled from command line, you use Team/Share, say 'Git!' and all is well.

I think I see what's the source: hierarchy is a problem for projects inside the workspace, not 'existing projects' that you import.

Here's a typical workflow:

  1. use git svn clone to get a tree. it's a stock, hierarchical mvn multi-module tree
  2. in eclipse, use import/maven/existing maven project. Point at the whole tree
  3. select all
  4. OK

it works fine. The nesting does not disturb eclipse one bit. I don't know what problem that bz is pointing at.

Before I used m2e I used the maven-eclipse-plugin. And it also worked in these cases, because it does not generate a .project/.classpath for <packaging>pom</packaging> aggregating projects, so Eclipse is never called upon to actually nest anything.

I'm not alone -- see the developer setup instructions as cxf.apache.org for an open source example that you can try for yourself.

Solution 2

Is it possible that you are working with old versions of the tool?

I have a Maven multi-module project that I work with using Eclipse 3.7 (Indigo), M2Eclipse (1.0) and EGit (1.0).

On the file system the multi-module project has a single parent directory.

In Eclipse I have separate projects for each module.

M2Eclipse does the dependency management perfectly.

There is single git repository (.git directory) at the top-level and EGit works perfectly.

Solution 3

You can put your modules in Git with hierarchical layout. And build those modules by Maven. If those modules are projects(whatever java, c++ or php project) recognized by Eclipse, they can be imported into workspace as flat layout in workspace.

-- the root of Git working directory
  -- moudule1
    -- project1(a java project)
      -- .project(a project file recognized by eclipse JDT)
      -- pom.xml
    -- project2(a java project)
      -- .project
      -- pom.xml
  -- module2
    -- projectA(a java project)
      -- .project(a project file recognized by eclipse JDT)
      -- pom.xml
    -- projectB(a c++ project)
      -- .project(a project file recognized by CDT)
      -- pom.xml 
Share:
11,839
ccleve
Author by

ccleve

Updated on June 07, 2022

Comments

  • ccleve
    ccleve almost 2 years

    We've got a multi-module project using Eclipse and Maven. The only way I could get it to work in the past was to use a flat layout for the projects, where the parent module was a peer to the other modules. This worked fine with m2eclipse and Subversion.

    Now we'd like to move to Git and GitHub. I'd like to expose the entire project, along with all the modules, as a single project on GitHub. The problem is that EGit, the Eclipse/Git plugin, wants to manage projects one at a time, not groups of projects, and so if you've got a flat layout, you can't do it.

    The right answer is to use a standard Maven hierarchical layout and manage the parent and all the modules as a unit. But Eclipse doesn't like that, and no amount of fiddling will get Eclipse to accept nested projects. m2Eclipse does not support hierarchies: https://issues.sonatype.org/browse/MNGECLIPSE-2291

    So what do you do? Do Git from the command line and abandon the ability to see what files have changed in Eclipse? Or abandon Eclipse?