Getting started with La Clojure
This guide takes you step by step through creating a La Clojure project using IntelliJ IDEA, La Clojure and Leiningen plugins.
- You are working with IntelliJ IDEA Community Edition or Ultimate Edition version 12 or higher.
- Leiningen is installed on your computer.
Creating a Leiningen project
Outside of IntelliJ IDEA, perform the following lein command to create a new lein project:
lein new foobar
The new lein project foobar is created under the directory C:\lein_project:
Open for editing the file project.clj, and specify the desired version of Clojure:
Installing La Clojure and Leiningen plugins
IntelliJ IDEA starts and displays the Welcome screen, where you click the link Configure:
2. In the Configure page, click the link Plugins:
3. Note that La Clojure and Leiningen plugins are not bundled with IntelliJ IDEA. They should be downloaded from the Jetbrains repository and installed. This is how it's done:
In the Plugins dialog box, click the button Browse repositories, to show the list of repository plugins.
Find the La Clojure plugin, download and install it:
Then, same way, download and install the Leiningen plugin.
When both plugins are installed, they appear in the list of available plugins. When you apply changes, IntelliJ IDEA prompts to restart, for the newly installed plugins to take effect:
Opening project in IntelliJ IDEA
On the Welcome screen, click Open Project:
Since La Clojure plugin has been installed, IntelliJ IDEA now recognizes the La Clojure projects:
On clicking OK, IntelliJ IDEA opens the new project, and shows its structure in the Project tool window:
Try to run core.clj, and you will immediately get an error message: No jdk for module 'foobar'. So let us define a suitable JDK for the project.
To do that, on the main toolbar click the Project Structure button :
The Project Structure dialog opens the Project page, with the missing JDK. Click New, on the pop-up menu, choose JDK, and then select the preferred JDK on your file system:
Note that JDK you've just added as the project JDK, appears in the SDKs page of the Project Structure dialog. Open the SDKs page to explore the constituents of the selected JDK:
Exploring module dependencies
You see that Leiningen La Clojure version 1.5.1 is added as the module dependency:
You can also observe this library in the tree view of the external libraries in the Project tool window.
Using La Clojure console
As the La Clojure plugin is installed, it adds new items to the IntelliJ IDEA UI. In particular, under the Tools menu, you can find the command that lets you launch the REPL console:
The console features undo/redo (Ctrl+Z/Ctrl+Shift+Z), code completion (Ctrl+Space) and history of entered commands (Up/Down):
Creating and running La Clojure code
Let us create a source file with some La Clojure code. To do that, select foobar package, and choose New | File on the context menu. Specify the file name and extension: let it be, say, hw.clj. As you see, IntellyJ IDEA immediately opens the new file for editing, and marks it with the dedicated icon.
Type the following code in the created file:
(defn hello-world  (println "Hello world"))
Mind the code completion and syntax and error highlighting in the La Clojure code!
Next, on the Tools menu, point to Clojure REPL, and then choose Load file to REPL. The new file is loaded into the interactive console and immediately run:
You can also select this code in the editor, and choose Run selected text in REPL: