Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prepare dependencies before playing in a Intellij Idea repl?

Say I want to play with a some clojure library, but inside the REPL from Intellij Idea. How do I start that REPL prepared? Or for that matter, how I load that library anyway, even after the start?

like image 687
Belun Avatar asked Feb 23 '23 23:02

Belun


1 Answers

With IntelliJ, library directories inside the project can be included in the Java classpath that's used when starting the REPL. These can then be used in the REPL through Clojure's "use" or "require".

The easiest way to get the libraries into the project is through Leiningen and IntelliJ's Leiningen plug-in. Leiningen is a build and dependency management tool for Clojure.

Download and install Leiningen. Install IntelliJ's Leiningen plugin. Open IntelliJ's setting screen and under IDE Settings > Leiningen, enter the path to the Leiningen executable.

From the IntelliJ project window, create a Clojure file named project.clj in the root. Edit this file using the Leiningen syntax to define the libraries that project depends on. Use the Leiningen library name from the library entry at clojars.org (the main clojure library repository), or the project's webpage.

From the Leiningen plug-in menu, add (+ icon) the project.clj. Now in the Leiningen plugin screen, click the project name to open it's tree, choose the "deps" option, and click the "play" icon from the menu. This will make Leiningen download the libraries, and place them in the correct (/lib) folder of the project.

Now rightclick the project name in the project windows, choose Open Module Settings > Modules > Dependencies > Add > Library > Name (Enter name) > Attach Jar Directories (Choose /lib)

Then start the REPL, load the library with "use" or "require" and you're all set.

like image 73
NielsK Avatar answered Apr 29 '23 03:04

NielsK