IntelliJ IDEA is a powerful integrated development environment (IDE) for Java. We will use it in the second half of the course. This page contains instructions required to set up IntelliJ projects, while installing the required libraries for the course (namely, JUnit and the Java functional standard library), as demonstrated in the workshops. It also includes some instructions to write and execute tests using JUnit. Installation instructions of IntelliJ and Java JDK can be found here.

The screenshots in this guide correspond to a specific version of IntelliJ IDEA Community Edition, and on a certain system. Things may look different across systems and versions. While the core functionality should remain the same, you may need to explore a little to find the corresponding buttons in the GUI of your IntelliJ software.

Creating an IntelliJ Project#

For assignments and workshop practice exercises, you will be asked to either (1) Clone an existing IntelliJ project Git repository (typically available in your GitLab user account, after forking a Git scaffold repository provided to you). (2) Create a new IntelliJ project from scratch. Instructions are provided below for each case.

Clone an existing project#

  • Go to the File menu.
  • In the drop-down list, navigate to New -> Project from Version Control...,
  • Enter the URL of the Git repository to be cloned. (We typically use HTTPS).

These instructions will create new IntelliJ project directory (where the different relevant files and folders of the project are stored). The project directory is shown in the Project sidebar (usually on the left of the IntelliJ main window).

An IntelliJ project directory typically includes, among others:

  • .gitignore file (when the project is associated to a Git repository, as in this case).
  • src folder: used to store Java source files of the project (separate from where IntelliJ stores the compiled class files).
  • tests folder: used to stored Java source files with JUnit tests for the project (more details on this later).

Create a new project#

  • In the welcome screen (the one that appears right after you start IntelliJ), click New Project. Alternatively, go to the File menu, and in the drop-down list, navigate to New -> Project....
  • Enter the project Name.
  • Enter the project Location in the file system (absolute path).
  • Select Language: Java.
  • Select Build system: IntelliJ.
  • Select the JDK version used in the course (e.g., 23.0.X for 2025S1).
  • Check the Create Git repository check-box.
  • Click the Create button.

welcome page

Once we have completed these steps, the project is opened, and the newly created project directory will be shown in the Project sidebar (just as above when cloning an existing repository).

folders for a new project

Newly created IntelliJ projects do not contain the tests folder by default. Thus, we need to create the tests folder manually. You can do this by right-clicking on the project name in the Project sidebar, and then, in the drop-down list, navigate through New -> Directory. Finally, select tests as the name of the folder.

Configurations#

Basic project configurations#

Go to File -> Project Structure:

  • In the Project tab, select SDK default for Language level and click Apply.
  • Mark sources/tests folders in Modules > Sources tab. To this end:
    • Select the src folder, and Mark it as Sources (if not already marked).
    • Select the tests folder, and Mark it as Tests.
    • Click Apply.

Project Structure

project settings

modules settings - marking source and test folders

Setting up libraries#

Most of the course projects use JUnit and (optionally) the Functional Java Standard Library.

Steps for adding the JUnit Library (from Maven)#

  • Go to Project Structure again, and select the Libraries tab.
  • Click +, and select From Maven (for New Project Libraries)
  • Input org.junit.jupiter:junit-jupiter:5.9.0 and search (or, a substring like org.junit.jupiter and find it from the list of result). Allow some loading time before the results are shown.
  • Click OK, and OK again in the confirmation box. Now you should see JUnit in Libraries.

Add Maven

Add JUnit library

JUnit added

Steps for adding the Functional Java Standard Library (from jar file)#

  • Create a new directory in the project’s root directory (named as, e.g., library). You can do this by right-clicking on the project name in the Project sidebar, and then, in the drop-down list, navigate through New -> Directory. Finally, select library as the name of the folder.
  • Download the jar file: by clicking on the jar for intelliJ link in the Functional Java course web page, and place it into library/. NOTE: do NOT add it to Git. Prevent having it in Git by adding a line e.g., *.jar into .gitignore (to exclude all jar files).
  • Again, Go to Project Structure, and select the Libraries tab.
  • Click +, and select (for New Project Libraries) Java Library.
  • Look for the path to the JAR file (/`library`/`comp1110.jar`) and click **Open**.
  • Click OK, and OK again in the confirmation box. Now you should see the standard library in Libraries.

Downloaded functional java JAR file to the project. Make sure to press Cancel when IntelliJ asks you about adding it to Git

Select the JAR file

Both libraries added

Writing Java Code#

Create a new file to write some codes (Example: a Rectangle class which imports the Functional Java Standard Library). To this end:

  • Right click on the src folder, select New, Java Class (named as Rectangle in this example)
  • Write some Java code, e.g.:
import static comp1110.lib.Functions.*;
  
public class Rectangle {
    int width;
    int height;
    Rectangle(int width, int height) {
        this.width = width;
        this.height = height;
    }

    int area() {
        return width * height;
    }
}

Test Java Code#

Create a new file for tests:

  • Right click on the tests folder, select New, Java Class (named RectangleTests in this example).
  • Write some code for testing the Rectangle class instance methods:
public class RectangleTests {
    @Test
    void testArea() {
        Rectangle rect = new Rectangle(5,10);
        assertEquals(50, rect.area());
    }
}
  • Important Note: IntelliJ provides automatic suggestions when you try to use an unimported method from the default/added libraries.
    • For example, if you use assertEquals() without imports, it will be shown in red.
    • You can hover over the method name to see a suggestion: “Import static method org.junit.jupiter.api.Assertions.assertEquals” and apply it.
    • After applying the suggestions for assertEquals() and @Test in the code, the following lines for imports will be added:
      import org.junit.jupiter.api.Test;
      import static org.junit.jupiter.api.Assertions.assertEquals;
      

      IntelliJ import suggestions

  • Running Tests:
    • Click the Play Button next to the testArea method to trigger that particular test. (Or next to the test class to run all tests)
    • The results show whether the test passed (with green ticks), failed, or failed to compile.

      Test results window (pass)

Submitting your project - pushing onto GitLab#

To push your local code onto a remote repository, you need to:

  1. Set up a corresponding remote repository (only need to do this once for each project),
  2. (add and) commit relevant changes, and push (whenever there are changes).

Set up remote#

The following instructions are needed only for projects created locally and without a corresponding repository online (i.e., not needed if the project is cloned).

  • First, create a remote repository on GitLab. To this end:
    • Create a blank project using this URL in the browser https://gitlab.cecs.anu.edu.au/projects/new#blank_project
    • Input name (and slug) (e.g., comp6710-2025s1-p3), set Visibility Level to Private, and uncheck "Initialize repository with a README"

      Create project on GitLab

      Copy URL of GitLab project

  • To add the remote repository to your project using the IntelliJ GUI:
    • Go to the Git menu, and select Manage Remotes...
    • Enter the URL to your repository, and add it for Origin.
    • The URL to the repository can be found on the project page on GitLab. (We typically use HTTPS, but you may also opt to use SSH)

    Manage Remote: add remote repository

Commit, Push#

  • On the Git menu, click Commit:
    • Select the files with changes you want to commit - this may be everything in “Changes”, but you should check and exclude any unintended ones (e.g., out/, library/). This happens if .gitignore is/was not set up correctly.
    • Enter a commit message
    • Click Commit and Push (or just Commit without pushing, if intended).

Git Commit window

Terminal commands as an alternative#

Sometimes, the built-in Git features in IntelliJ may not behave as expected. In such cases, using Git commands directly in the terminal can serve as a reliable and flexible alternative.

You can use either the built-in terminal in IntelliJ or your system’s native terminal.

  • To add a remote repository: Open the Terminal, and enter the command: git remote add origin <address_to_your_repo>

Other commonly used commands are introduced in the Course website, Git and Notebooks.

Other info about IntelliJ#

  • (Optional) You may find it worthwhile to get yourself familiar with the IntelliJ Shortcuts and appearance-related configurations.

  • For example, you can add a “Git Push” icon to the main toolbar on the right.

    Build project icon

  • When you build the project (Build > Build Project, or clicking the hammer icon for build), an out folder will be generated/updated. It contains the compiled class files, and should be ignored (in .gitignore) by Git.

Build project icon

bars search caret-down plus minus arrow-right times