Programming Languages

Setting Up Clojure with IntelliJ IDEA

For this course we will be using the Clojure programming language with the IntelliJ development environment. IntelliJ is available for Windows, macOS, and Linux.

Installation

  1. Download and install the Community edition of JetBrains’ IntelliJ IDEA for your operating system. Use all the default options when installing the program.
  2. The first time you run IntelliJ select the Plugins option from the Configure menu at the welcome screen:

    Select the Marketplace tab from the plugins window and search for cursive:

    Install the Cursive plugin using the Install button. Press the Restart IDE button when it appears.

Project Creation

  1. Download and extract the Clojure SDK files.

  2. In the welcome screen select the Create New Project option.

  3. From the New Project window, select the Clojure option from the left panel, then select Bare project from the middle panel, and finally press the Next button.

    Type in the Project name and Project location fields. Select the Use library radio button and press the Create... button.

    In the New Library Files window, go to the clojure_sdk_files directory (from step 1) and select the five JAR files contained there (use the Ctrl key to select multiple files):

    • clojure-1.10.0.jar
    • core.logic-0.8.11.jar
    • core.specs.alpha-0.2.44.jar
    • math.numeric-tower-0.0.4.jar
    • spec.alpha-0.2.176.jar

    Press the OK button and then Finish.

  4. The first time you create a Clojure project a Licence Required message will appear at the bottom of the main window inside an event log pane.

    You’ll need to request a licence for Cursive. Follow the previous link, and in the Choose licence type option select Non-Commercial because you’ll be using Cursive for student work (and otherwise you’d have to pay $99 USD for it!). You’ll receive the licence in your e-mail.

    Once you’ve gotten the licence, go back to the event log pane, click on the activate it link and copy/paste your Licence Certificate.

Using the REPL (Read-Eval-Print-Loop)

  1. In IntelliJ’s main menu choose Run and then select Edit Configurations... In the Run/Debug Configurations window, press the plus symbol (+) at the top left corner and select Clojure REPL and Local.

  2. Specify a Name (for example The REPL) and select the nREPL radio button. Press the OK button.

  3. Press Shift+F10 to open the REPL window for the first time.

Using Clojure Source Files

  1. To create a new Clojure source file, expand the project in IntelliJ’s left hand panel and select the src directory. Then, from the main File menu select New followed by File. Type the file name in the dialog window. NOTE: Clojure source files should have a .clj extension.
  2. To send your file’s contents to the REPL, open the editor’s context menu (mouse right-click) and select REPL and Load file in REPL.
  3. To run the program contained in your file, press Ctrl+Shift+F10, or you can also use the editor’s context menu.