rishat
rishat

Reputation: 8376

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?

Upvotes: 3

Views: 1428

Answers (2)

BillRobertson42
BillRobertson42

Reputation: 12883

Managing this by hand is not difficult. As you said you simply open your project.clj file in your editor and add dependencies.

You can find the current version by either checking the project's page or by searching for it on clojars' or maven's website. If you know what you need it only takes a few minutes, and if you're not writing throw away code a few minutes is nothing compared to the life of the project.

To maintain dependencies, something like lein ancient is very helpful.

Upvotes: 1

user2609980
user2609980

Reputation: 10474

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.

Upvotes: 5

Related Questions