How to import a Maven project from GitHub into Eclipse

One of the first things a developer will be told after they join a new software project is to head over to team’s GitHub or GitLab repository and bring the latest version of the app into their local workspace.

If the project in question is Apache Maven based, it’s hosted in a Git based repo like GitHub or GitLab, and the IDE of choice is Eclipse, then the process is actually a fairly simple one.

How to pull Maven projects from GitHub into Eclipse

To bring a GitHub hosted Maven project into Eclipse, follow these steps:

  1. Copy the GitHub URL of the repository to the clipboard
  2. Open Eclipse and choose Import –> Projects from Git (with smart import)
  3. Choose the Clone URI option in the Git import wizard and click Next
  4. Confirm the URI, Host and Repository path parameters and click Next
  5. Choose the Git branches to clone from the remote repository and click Next
  6. Confirm the Directory into which the repository will be cloned and click Next
  7. Choose the Maven project to import into Eclipse from GitHub and click Finish
Maven Eclipse GitHub import

The smart import option simplifies the task of pulling a Maven project from GitHub into Eclipse.

After the Finish button is clicked, a few disconcerting error messages may appear in the Tasks window, but don’t let them startle you. After Eclipse imports a Maven project from GitHub, the project’s pom.xml file gets processed, and missing dependencies are pulled down from Maven central. Until these dependencies are fully downloaded and installed in the local Maven repo, error messages will appear.

To monitor the progress of the Maven build, monitor the progress bar in the bottom right-hand corner of Eclipse. When the build is complete, any errors should disappear.

Import multiple Maven projects from GitHub

It’s worth noting that the process described here will work both with single project repos and with GitHub repositories that contain multiple Maven projects.

As a best practice, especially for cloud-native microserivces that comply with the 12-Factor App methodology, there should only be one project per repo. However, it’s not uncommon multiple Maven projects to be contained in a single Git or GitHub repo, especially if the projects are used for learning or prototyping. If there are multiple projects in the repo, Eclipse’s smart import allows the developer to explicitly choose which repositories to import.