Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manage dependencies in `project.clj` from the command line

I would like to search and install clojure dependencies from the commandline.

Does there exists a tool/leiningen command/lein change script?/... that can:

  • search for clojure libraries online
  • rewrite project.clj to include the dependency (latest version)
  • update dependencies?

Much along the lines of npm install --save (--save-dev) and npm search, for those that are familiar with npm (JS/Node package manager).

(Maybe boot provides a more npm-like workflow?)

like image 530
wires Avatar asked Feb 13 '15 18:02

wires


2 Answers

You could find complete list of all Leiningen plugins at its Plugins Wiki page.

I just looked through Development Tools section and found two plugins that may interest you:

  • lein-plz - a Leiningen plugin for quickly adding dependencies to projects.
  • lein-ancient - a Leiningen plugin to check your project for outdated dependencies and plugins.

And here is an example of adding new dependencies with lein-plz (from its Readme):

$ lein plz add core.async cljs data.json

And an example of updating outdated dependencies with lein-ancient (from its Readme):

$ lein ancient upgrade-profiles [<options>]
like image 69
Leonid Beschastny Avatar answered Nov 15 '22 08:11

Leonid Beschastny


OK, based on clarifications in the comment, I would suggest looking at some of the clojure linters. While most focus on your project code tree, some will also examine your project.clj file. There is no one tool I can think off, but there are a number of separate tools which can help with little parts of what your after. You can use lein tasks and aliases to automate some of the process and if your using emacs, there are some add ons that will help a bit.

  • Eastwood: This one has a milestone to add functionality which will examine the :dependencies section in your project.clj and identify dependencies which are not being used. While not implemented yet, it is worth keeping an eye on and I think it is a useful plugin (written by the author of lein btw)

  • slamhound: This plugin will examine your namespace declarations and clean them up so that they only contain things which are required. A prerequisite for any tool which might be able to re-write your project.clj file IMO

  • kibit and bikeshed: these two will look for possible cleanup and code improvements to help keep your code consistent and more idomatic

Many of these types of tools can be useful, but their effectiveness can be limited by the 'quality' of your clojure code base. I find you get better results with such tools if your code is as consistent and idiomatic as possible. Running bikeshed -> kibit -> slamhound -> eastwood seems to provide good functionality for me.

If your using emacs, you might also find clj-refactor.el useful. Also note that lein does have a search facility - it can be slow if the indexes need to be updated, but after that is quite fast. However, it isn't that functional as a general search facility, but if your just looking to find the library name and version so that you can add them to your dependencies, it can be pretty useful - in the case when I'm looking for a library to solve a problem (as opposed to a specific known library when I just need to get the name and version number) I tend to just use google and some of the sites out there which collect info on available libs.

like image 44
Tim X Avatar answered Nov 15 '22 09:11

Tim X