# CSE 373, Autumn 2018: Eclipse load from git

## Opening code from git

This section of the guide covers how to open code a git repository in Eclipse. It is very important that you DO NOT simply open the project: instead, you must import the code as a general project.

You should also make sure you're connected to the internet when performing these steps. When you're importing the example, Eclipse will automatically try and download some libraries you need to run your code.

### Step 0: Set up SSH Keys

If you have not already done so, follow step 4 of the Eclipse setup instructions to set up SSH keys on your machine and add them to Gitlab.

### Step 1: Checkout code using Eclipse Git

2. Under the name of the project, there is a text box with a dropdown to its left. Make sure the dropdown says "SSH", then copy the string in the textbox. It should look something like "git@gitlab.cs.washingt.n.edu:...".
3. Run Eclipse. Select the "File" > "Import" option from the menu:

4. Select the "General" > "Projects from Git" option.

5. Select the "Clone URI" option and click next.

6. Now paste the string you copied from Gitlab into the "URI" text field (Eclipse may paste it automatically). The rest of the text fields will automatically populate themselves, click "Next".

7. Click "Next".

8. You should now be at a page called "Local Destination". Here you can set the directory you would like the project to be downloaded to. Remember (copy) which directory you choose, you will need it later. Click "Next" again once you have chosen a location for your project.

9. On this page, some time will pass as a green bar fills up at the bottom. This is Eclipse downloading your project to the location you have selected. Once this is finished, you should be at a page that looks like this:

IMPORTANT: click "Cancel" to exit the wizard. We need to exit now because the Git wizard does not know how to import Gradle projects properly.
10. ### Step 2: Import the Gradle project

11. Select the "File" > "Import" option from the menu again:

13. Hit "Ok" and "Next" until you encounter the below dialog (it may start on this page if this is not your first Gradle import). Click the "Browse" button:

Here is where you need the directory your project was downloaded to. Navigate to where your Gitlab project is located and select it.
14. Click Next.

15. Click Finish.

16. Importing a Gradle project can take a bit of time. There may be a green progress bar in the bottom right corner of your screen. Eventually, your project will appear in the "Package Explorer" panel of Eclipse, next to your other projects. You will also notice that the project name has a yellowed-out "[repository-name master]" next to it. This tells you that the project is under version control.

17. Here is how the project repo looks when some folders are expanded. Your project/repository name would be different.

#### What is a 'gradle project'?

Note: this box contains optional background information: you do not need to know any of the information presented here.

When working on larger projects, programmers tend to face a few different problems:

1. How do you keep track of what 3rd party libraries the project needs installed?
2. Each IDE stores its project config in a slightly different way. How can you make sure your project can run on all kinds of different IDEs, including ones you've never heard of, with minimal fuss?
3. Sometimes, building our project and producing a final JAR we can give to our users can require running multiple instructions/performing several complex steps. Instead of having to do that manually, can we just write a script that does this all automatically for us?

It turns out that we can use the same tool to answer all of these questions: we can use a build manager. Basically, what happens is that we record all of the libraries we need, all project configuration, and all build instructions inside of a special file our build manager understands.

Conveniently, it also turns out that all (modern) IDEs have great support for a wide variety of popular build managers: they can read the special file and automatically convert all of those instructions into their IDE-specific configuration.

In our case, we're using a build manager called "gradle". Try opening up build.gradle inside of your project. If you skim through it, you can see that the file configures a variety of things and specifies a handful of 3rd party libraries we want to install and use. (We've commented this file fairly heavily in case you're curious).

Gradle isn't the only build manager – other popular build managers for Java include Ant, Maven, and Ivy.

If you start working with other programming languages, you'll learn that they all also have their own build managers and conventions for managing large projects. However, at a high level, they all work in the same way: you specify the libraries you need and your build instructions in some file(s), and run some sort of build tool to manage everything for you.