Eclipse + Maven + Git + 多模块项目 = 不幸

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7841440/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:05:48  来源:igfitidea点击:

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

eclipsegitmavenegitmulti-module

提问by ccleve

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.

我们有一个使用 Eclipse 和 Maven 的多模块项目。过去我可以让它工作的唯一方法是为项目使用平面布局,其中父模块是其他模块的对等体。这适用于 m2eclipse 和 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.

现在我们想转移到 Git 和 GitHub。我想将整个项目以及所有模块作为 GitHub 上的单个项目公开。问题是 Eclipse/Git 插件 EGit 想要一次管理一个项目,而不是一组项目,所以如果你有一个平面布局,你就做不到。

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

正确的答案是使用标准的 Maven 分层布局,并将父模块和所有模块作为一个单元进行管理。但是 Eclipse 不喜欢那样,再多的摆弄也不会让 Eclipse 接受嵌套项目。m2Eclipse 不支持层次结构: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?

所以你会怎么做?从命令行执行 Git 并放弃查看 Eclipse 中哪些文件发生更改的能力?还是放弃Eclipse?

采纳答案by bmargulies

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.

作为单个 git 存储库的标准 Maven 多模块结构在带有 M2e 的 Eclipse Indigo 和该环境中显示的 git 插件中非常适合我。你不能要求 Eclipse 为你做你的获取,但是一旦你'从命令行拉出,你使用团队/共享,说'Git!' 一切都很好。

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
  1. 使用 git svn clone 获取一棵树。这是一个库存的、分层的 mvn 多模块树
  2. 在 eclipse 中,使用 import/maven/existing maven 项目。指向整棵树
  3. 全选
  4. 好的

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

它工作正常。嵌套不会干扰eclipse。不知道bz指的是什么问题。

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.

在我使用 m2e 之前,我使用了 maven-eclipse-plugin。并且它在这些情况下也有效,因为它不会为<packaging>pom</packaging>聚合项目生成 .project/.classpath ,因此 Eclipse 永远不会被要求实际嵌套任何内容。

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

我并不孤单——请参阅 cxf.apache.org 中的开发人员设置说明,了解您可以自己尝试的开源示例。

回答by Sri Sankaran

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

我有一个使用 Eclipse 3.7 (Indigo)、M2Eclipse (1.0) 和 EGit (1.0) 的 Maven 多模块项目。

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

在文件系统上,多模块项目有一个父目录。

In Eclipse I have separate projects for each module.

在 Eclipse 中,我为每个模块都有单独的项目。

M2Eclipse does the dependency management perfectly.

M2Eclipse 完美地完成了依赖管理。

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

顶层有单个 git 存储库(.git 目录),EGit 完美运行。

回答by Kane

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.

您可以将模块放入具有分层布局的 Git 中。并通过 Maven 构建这些模块。如果这些模块是 Eclipse 识别的项目(无论是 java、c++ 还是 php 项目),它们都可以作为工作区中的平面布局导入到工作区中。

-- 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 

回答by Mickael

For Maven projects, multiple imports at once can be achieved via the Maven import wizard (that is accessible from Git). In case you don't know what kind of projects you're about to import, you can use the new Easymport that will import project "as best", by deducing configurations from various files. See https://github.com/jbosstools/jbosstools-playground#easymport-easy-and-smart-openimport-of-a-project

对于 Maven 项目,可以通过 Maven 导入向导(可从 Git 访问)实现一次多次导入。如果您不知道要导入什么类型的项目,您可以使用新的 Easymport,通过从各种文件中推断配置,将“尽可能地”导入项目。见https://github.com/jbosstools/jbosstools-playground#easymport-easy-and-smart-openimport-of-a-project

Once you get all those projects, you can use the Nestor plugin, which will show project in a nested/hierarchical layout, mapping more correctly your Maven project: https://github.com/jbosstools/jbosstools-playground#nestor-view-nested-projects

获得所有这些项目后,您可以使用 Nestor 插件,它将以嵌套/分层布局显示项目,更正确地映射您的 Maven 项目:https: //github.com/jbosstools/jbosstools-playground#nestor-view-嵌套项目