CSE 373, Winter 2019: IntelliJ Project Import Guide

Workflows

After you've obtained the assignment code, there are two possible ways to load that code in IntelliJ: either as a whole project, or as a single module in a project. IntelliJ can only open one project in each window, but each project may have multiple modules.

We recommend importing our code as separate projects, since our assignments contain duplicated files that sometimes confuse IntelliJ, however you may choose to use a single project if you wish; see the bottom of the page for instructions. (Benefits of the single-project workflow include only needing to set our settings for a single project instead of all new projects, and having the ability to view files from all assignments in the same IntelliJ window.)

Importing a new project

This section of the guide covers how to import code as a new project. Note that you should import the project the first time instead of simply opening it. Opening a project will attempt to open it as an existing IntelliJ project, which may cause issues if your partner accidentally commits his/her IntelliJ project files, whereas importing will guarantee that you create a new project. (On the other hand, if you've already imported the code on your machine before, you should open the project instead of re-importing it.)

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

  1. Run IntelliJ. If you're on the welcome screen click "Import Project":

    If you have another project open, click "File" > "New" > "Project from Existing Sources...":

  2. Navigate to and select the folder containing the code, and then click "OK". There should be a build.gradle file directly inside that folder. (You may also select the build.gradle file instead if using the folder doesn't work.)

  3. Make sure that "Gradle" is selected on the next screen, then click "Next"

  4. Make sure that "Use auto-import" is checked and that "Use gradle 'wrapper' task configuration" is selected, then click "Finish".

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: 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 Java build manager—other popular build managers 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.

Single-project workflow

This section of the guide covers how to import code as a new module. Before importing a module, you must first have a project that will contain that module.

  1. Run IntelliJ. If you don't already have the project that you will be putting your module into, you'll need to create a new empty project. If you're on the welcome screen, click "Create New Project":

    If you have a project open but you want to create another new one, click "File" > "New" > "Project...":

    In both cases, you'll be brought to a new screen to choose the project type. Select "Empty Project":

    Now choose a name and location for the project. The folder you choose does not need to be empty: IntelliJ will just create a .idea folder in your selected location. The location you choose can be the folder that will contain your assignments, or somewhere else entirely; it doesn't really matter as long as it won't get deleted or moved, and you can find it later.

    If you already have a project that you want to import other modules into, just open that project ("Open????" from the welcome screen, or "File" > "Open..." from the editor)

  2. If you've just opened the new empty project, IntelliJ should automatically open the "Project Structure" window with the "Module" item selected. If not, open this window from "File" > "Project Structure", then select the "Module" item.

    Click the "+" button, then "Import Module":

  3. Navigate to and select the folder containing the code, and then click "OK". There should be a build.gradle file directly inside that folder. (You may also select the build.gradle file instead if using the folder doesn't work.)

  4. Make sure that "Gradle" is selected on the next screen, then click "Next"

  5. Make sure that "Use auto-import" is checked and that "Use gradle 'wrapper' task configuration" is selected, then click "Finish".