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

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?

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:
use git svn clone to get a tree. it's a stock, hierarchical mvn multi-module tree
in eclipse, use import/maven/existing maven project. Point at the whole tree
select all
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.

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.

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

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

Related

Importing multimodule maven project from Git into Eclipse/STS

I have been desperately trying to import a multimodule maven project from GIT into my (freshly installed) STS 3.9.4.
During the last hours I tried lots of solutions that were posted on stack overflow, but none of them worked for me.
These are the steps I did:
git cloned the repo from the command line (intentionally, because it didn't work either when I used the GIT integration of STS)
imported the project via File / Import / Maven / Existing Maven Projects
After the project was imported, it looks like this:
(please ignore the red icon at the top left, the problems persists even when this icon is not there)
I can Run As / Maven Install any pom.xml, but when I try to edit java sourcecode Eclipse tells me The resource is not on the build path of a Java project.
To fix this I tried:
convert to faceted form
added Java nature
Configure Build Path / Set as source folder
add buildcommand org.eclipse.jdt.core.javabuilder to .project
Being able to build is fine, but editing sourcecode without support for Organize Imports, Format Source, and so on is a real pain.
From your screenshot I assume the modules are nested within the directory of the reactor pom(=parent pom) and you have imported all of them as projects (reactor and modules).
Don't add a java builder to the "reactor" project.
Make sure not to open the java files from the projects corresponding to the reactor pom, but from src folder within the corresponding module projects.
The solution to this problem was somehow hidden, but in the end I have to say the reason was clear.
After I checked with a different multimodule project (https://github.com/Activiti/Activiti.git), I was sure that my STS and other components don't suffer from a generic problem. So the cause must be located in the project itself.
The multimodule project was setup correctly on the pom.xml level. But the topmost pom.xml was modified: most of the modules had been commented out:
The developer who introduced that change didn't experience any problems because he kept his already existing workspace. And the problem only occurs when a new workspace gets created and maven scans the pom files.

are there different ways of importing git repository to Eclipse?

Why when I import a git project it does not appear like full package path view (main.java.comformance) like this image:
I have imported this project before but now in the package view, it only appears as a tree of folders and not full package path view like main.java.comformance with package icons. I wonder what I'm doing differently now. I followed the instructions in this video: https://www.youtube.com/watch?v=L8IeaWHZCRo)?
Both projects on the screenshot do not seem to be configured correctly (probably because they were not created with Eclipse or files like .project were not shared):
The project on the right side is obviously a Maven project (with probably this pom.xml file): the Java source folder should be src/main/java/ (default of Maven) instead of src (default of Eclipse) and the Java packages for instance uk.ac.manchester.cs.jfact instead of main.java.uk.ac.manchester.cs.jfact.
The project on the left side is not even configured as a Java project.
The simplest way is to use the Eclipse Smart Import feature (instead of configure everything manually): the Java nature of the project will be detected even without the .project file and also the pom.xml file is read to get the required JARs and to configure the Java build path and source folder(s) automatically:
Clone the Git repository
In the Git Repositories view right-click the Working Tree node and choose Import Projects...
Do you see the "J" in the icon next to the project name "jfact" at the right image?
That means that it is a "java" project. Eclipse does not know anything about your project.
You will have to do one of this:
Checkout the project again with Eclipse and use a "wizard" configuring it as a java project.
Enable Project Facets (right-click on the project name), and then enable "Java" in the Project Properties/Facets. This is not trivial, so I don't recommend this. - If this is a solution, actually I don't know for sure -
If you are using maven, close the project and execute mvn eclipse:eclipse to convert/create the project files for eclipse, and open again the project.
After you manage it to become a Java project, furter steps could be needed, but maybe will be enough.

How to import a maven project from SVN tags into eclipse?

(This may be a dumb question but I am not quite familiar with the interesting eclipse importing logic)
I am trying to read the source code of Netty, so I checkout the tag folder for Netty-4.0.24.Final from the Netty SVN (https://github.com/netty/netty).
The files are shown as below:
Since there's a pom.xml files there, I use the "import existing maven project" to import it into Eclipse.
But the imported result looks like this:
I am expecting some well-formatted package layout. What's wrong?
ADD 1
I found this thread: "Source folder is not a Java project" error in eclipse
It seems I need to manually turn on the Java Project Facet for each project in order to see source code organized in packages. But I am wondering does it have to be this tedious? Is there any simpler way to import a maven project and display it in packages?
It doesn't matter if you are using tag or latest branch, Netty project composed from a sub-projects you see in the worskpace
Yes each one is full Maven project on it's own and gets deployed as separate artifact into Maven repo. When you open any of them, there will be your familiar Maven folder structure.
Your highlighted pom.xml is multi-module project for all the sub-projects.
It's used to build all sub-projects in one go.
If want to get familiar with this concept: I would suggest this tutorial:
http://books.sonatype.com/mvnex-book/reference/multimodule.html
BTW, when you import sub-projects into Eclipse M2E plugin names projects according their artifact names, not according folder structure.

Eclipse m2e multi-module project checkout and convert to maven

I have recently had need to checkout an apache project to do some fact-finding/debugging (specifically maven-surefire-plugin, see this question). This, like most other apache projects, is a maven multi-module project. So, in eclipse, I open up the SVN Repositories browswer, add a new repository, find the project and right-click->Checkout.... In the wizard, I click Checkout as a project in the workspace and type in the name of the project.
I have the project, now I need to let eclipse know its a maven project, so right-click->Configure->Convert to Maven Project. Now the parent project is a maven project. I can right-click->Run As->Maven Build and it works. But, all the modules are just folders. Eclipse doesn't know anything about where the source code is or even if it has any. In a single module project it would have set the source folder, build folder and other configuration automatically. Further more, if you are creating a multi-module project from scratch, you start by creating the parent project, then, when you add modules to it, they each show up as individual projects in eclipse with the physical directory living under the parent project folder as needed by the default maven build process.
So now, knowing how its done when creating new projects I can File->New->Project..., choose General->Project, give the project a name (I match it to the module name), uncheck Use default location and set Location: to the path on to the module inside of the parent project folder. After clicking Finish, and repeating the process for each other module I have something that looks similar to what I would expect. I now need to convert every individual module to a maven module in the same fashion as the parent project. Great, they are all maven projects, right?
So then I open them up, and the source folder is not set.
Argh... Then I go to each project, twist it open, and on the src folder I right-click->Build Path->Use as Source Folder. Lather, rinse, repeat... Once done on all the projects, it really looks and feels like I started this project from scratch. Things function.
My question is, is it really this hard? Am I missing a shortcut? Wouldn't it make sense if Configure->Convert to Maven Project on the parent pom realized it was a multi-module project and did all the work for me? This is a very painful process for apache projects as they all seem to have many, many, modules... Anyone know of a better process?
You could try to pull all the code down outside of Eclipse, import the parent project as an existing Maven project (right-click -> Import... -> Existing Maven Projects), and see if it all comes in the way you expect. Then right-click -> Team -> Share Project... on the parent project.

Maven project is in a subfolder, can't get Eclipse integration to work

Inside the folder 'ProjectName' exists several subfolders, and of them contains java program:
ProjectName
Specifications
JavaCode
Gfx
...
JavaCode folder contains pom.xml.
I have installed m2eclipse (0.10.x) to Eclipse and imported whole ProjectName folder to Eclipse. Subfolders are displayed correctly but maven integration is not working correctly - for example I don't see src/main/java "shortcut" folder in Eclipse, but I have to click to open all folders.
If I create a new maven project with Eclipse from scratch, the integration works well.
What could be the issue?
Select the JavaCode folder and then invoke File... / Import... / Maven Project. That would bring your Java code into Eclipse as a proper project with Maven support enabled. It is fine to import several overlapping folders. So, you could use the parent for version control purposes and JavaCode would be the actual Java project you'd work with in the IDE.
Unfortunately there is no way around that, unless you want to move your pom.xml to the root project and remap all the Maven plugins to folders under JavaCode project. But that would be really bad idea and Maven integration for Eclipse may not work with such project structure without an additional tweaking.