Search code examples
clojuredependency-managementleiningenspacemacs

How do I add a new dependency to a Clojure project using emacs or lein?


I use emacs (to be more precise, Spacemacs), and so far, I haven't seen any way to add a project dependency (say, ring or hiccup) to my project, other than opening ./project.clj and adding a new vector to :dependencies. I'm not feeling comfortable doing this because I need to remember exact version of the package I want to add as a dependency, and multiplied by possible number of these packages, this amount of information is clearly not for a human head. Meanwhile, I have a strong feeling that it's possible to add a project dependency either via CLI or in emacs directly (perhaps Cider?). Is it possible, and how do I do this?


Solution

  • In Spacemacs you can use clj-refactor to help you with this. Navigate to your project.clj, cider jack-in with ,' and press ,rap (major mode, refactor, add, project dependency) for cljr-add-project-dependency.

    In the menu you can search for an artifact available in Clojars:

    Choose artifact

    and select one of the available versions:

    Choose version

    When you press enter the dependency is added to the bottom of the list.