Getting Eclipse, Maven, and Git to play nice together

I've read a lot of how-to guides and tutorials online that quickly tell you how to do something, making it look easy. Sometimes when I ask friends how to do something, they just say, "Oh you need that? You just install it. Easy."

I've heard coworkers and colleagues talk about how simple, how easy it is to use Tool X or Framework Y or Service Z.

I've heard coworkers and colleagues say Tool X or Framework Y or Service Z is a pain in the ass, don't use it.

I've even caught myself doing one or the other.

Well, in the spirit of documenting my success and my failures, allow me to present to you my journey to getting Eclipse, Maven and Git to work nicely together.

What's my problem?

It's always great to state the problem. Sometimes talking to your duck is all you need. Though my duck isn't going to save me here... But let's lay down the issue:

I have a project hosted in a Git repository somewhere (maybe on Github or Gitlab, our internal version of Github), and it's managed by Maven. How do I check it out using Eclipse? To be clear, I want both my Maven plugins to recognize it as a Maven project (download and resolve dependencies, recognize the pom.xml files) and I want my Git plugins to recognize that it's managed by Git, so I get history and revision info, etc.

Okay, let's begin

I went to the eclipse website and downloaded the top package, titled Eclipse IDE for Java Developers (Luna 4.4.1). I'll pick the 64 bit version because I have a 64 bit operating system.

I extracted it and fired it up. I created a brand new workspace.

Then I went to the options (Window -> Preferences) and saw that it recognized some settings for Git that I must have configured in a previous lifetime. If you haven't done this, just add some entries for your user settings (or System settings). I think those two settings are the most important.

Okay... so Git is there... how do I check out the maven project? Some Googling reveals this Stackoverflow discussion that suggests the M2Eclipse plugin. Do I have that installed?

Eclipse has a handy feature called Installation Details and can be accessed by Help -> Installation Details

Doh, not there.

Two options: I can try to install this plugin... Or maybe I should just try a different Eclipse package, perhaps the 'Eclipse IDE for Java EE Developers' as that looks to include a bunch of Maven integration tools. Ohh, and it also looks like the EE version includes JavaScript development tools, and I know we do a lot of JavaScript in our project, and bandwidth is cheap, so let's try this route.

I extracted it and fired it up. I created another brand new workspace, just to be safe.[1]

Out of curiosity I checked the Maven settings (Window -> Preferences again) and saw that it picked up on my user settings. This is good because we have an internal Maven repository where we keep our company .jars and a cache of approved dependencies, and those settings are in the Users\stephen\.m2\settings.xml file. Also some settings for our HTTP proxy, and when to use it. Looks good.

Then I tried to create a new project. I right-clicked on the empty Project Explorer view. New -> Project... -> Maven -> Check out Maven Projects from SCM.

I entered in the URL from gitlab. Strange, I have no idea what this box is for and why it's empty.

It let me click Next. At the next screen I accepted the default settings and clicked Finish.


Nothing. No projects or folders in the Project Explorer. I waited a moment. Maybe there's debugging info in the console? I had to open that up. Window -> Show View -> Console.

Nope, nothing in there.

Was that empty box indicative of a problem? What's an SCM Connector? If I Google 'SCM connector' I get that Stackoverflow question again, or this SO question, and the SCM tools section from Eclipse Marketplace... but nothing that tells me what an SCM connector is.

If I Google 'what is a SCM connector' I still don't get answers. I get the Apache Maven SCM configuration article that explains how to use a SCM Plugin.

What the heck is a SCM Connector?

This drives me crazy in software development. So many developers/tech evangelists are quick to tell you why you should use something, or how to use something, but always before telling you what it even is or what purpose it serves. Thank goodness I know what the acronym SCM stands for, or else I'd be lost even further.

From context alone let me tell you what I think an SCM connector is. First, SCM stands for Source Control Management and examples are Git or SVN (Subversion). Secondly a SCM Connector is the intermediary tool between Maven and your SCM. You can use Maven with Git, or you can use Maven with SVN, and the connector is just the tool or interface between the two. At least that's my guess.

Okay, so I click the link to the m2e Marketplace. Maybe I can find the Git <-> Maven SCM connector there.


That's a funny, not super helpful, error message. Failed to discover all connectors? All? Surely you mean to say: Failed to find ANY connectors. And surely you mean to tell me it's because of an HTTP error, possibly related to the fact that I'm behind a corporate firewall, right? Right?!

Now, I've ran into things like this before so I have a rough idea of what to do next. I'm not going to get so easily discouraged, but my developer friends or skeptics may, and here's the part where they spend hours scratching their heads or slamming their keyboard against the wall, hopefully persevering but potentially giving up and dismissing Git (or Maven, or Eclipse, or some other tool/framework/technology that's not even tangentially related but they have preconceived notions of being too troublesome, and not worth their time and energy, so it gets put on the shit-pile) and why can't they just go back to the days when version control was so simple, why do they have to learn something new?

After some digging around in Eclipse I think I found the proxy settings:

I hit apply and close it. I right-clicked on the empty Project Explorer view again. New -> Project... -> Maven -> Check out Maven Projects from SCM. I click on the m2e Marketplace link.

And... Nothing. What the heck? Let's go back to the Network Connections preference. What? The Host and Port are empty, but the User and Password are filled out?

Am I going crazy? Okay, let's try setting BOTH the HTTP and HTTPS proxy to use the same thing. I click Apply and OK again.

I right-clicked on the empty Project Explorer view again. New -> Project... -> Maven -> Check out Maven Projects from SCM. I click on the m2e Marketplace link and......

It works! Holy crap! I find the m2e-egit connector which I assume is what I want, only because it has the word Git in it. From context I'm guessing EGit is the name of the Git plugin for Eclipse. Purely out of curiosity I click the little info button which displays contextually relevant, super helpful information.

Heeheehee. That's not helpful at all.

Okay, the fourth time is the charm. I right-clicked on the empty Project Explorer view again. New -> Project... -> Maven -> Check out Maven Projects from SCM.

Woohoo! This looks promising. Turns out that blank field was a good clue. Okay, I click through these screens and....

Today is NOT my day! At last this error message is more helpful. Looks like a proxy error, probably related to not having turned off the proxy. A little strange, because I thought I had disabled the proxy for internal addresses (and this host is clearly an internal one). Both SSH/Git protocols should not be operating over HTTP. I thought the proxy was only for HTTP and HTTPS... But let's change those settings again.

I guess I don't have the proxy settings ignoring internal hosts correctly. Whatever. I just clicked the proxy settings to say Direct and hit Apply then OK.

Okay, fifth time is the charm. I right-clicked on the empty Project Explorer view again. New -> Project... -> Maven -> Check out Maven Projects from SCM. I click through these screens and....

Holy crap! It worked!

After a few minutes of copying the repository and building the project, everything is there. Maven recognizes it and the Git plugin recognizes it! Awesome.

[1] This is one of my rules to use Eclipse without going insane: Never fear creating new workspaces. Use the second, not accepted answer here to transfer your settings over quickly. You followed rule 2 right? You should be using a package manager / build tool to be able to checkout a project from scratch, resolve dependencies, and get it running in 5 minutes or less.