README.org

June 14, 2018 ยท View on GitHub

#+TITLE: Depify

*** What?

depify reads your [[https://leiningen.org][Leiningen]] project.clj configuration file and produces a deps.edn file suitable for the [[https://clojure.org/guides/deps_and_cli][Clojure CLI tools]].

deps.edn and the Clojure CLI tools have a narrower focus than Leiningen or Boot, but depify will do its best to produce a useful deps.edn replacement. This includes adding extra aliases to provide "missing" functionality. One such example is the addition of the :test and :runner aliases borrowed from Sean Corfield's [[https://github.com/seancorfield/dot-clojure/blob/master/deps.edn#L9-L19][dot-clojure]] repo. Other aliases may be added in the future - PRs are always welcome!

*** Changelog

  • 2018-06-13
    • Add ability to read lein pprint output from stdin (actually fixes #2)
  • 2018-06-12
    • Add ability to read project.clj from stdin (fixes #2)
  • 2018-06-11
    • Hefty refactoring (fixes #1 and many other issues)

*** Usage

Create an alias in your ~/.clojure/deps.edn map:

#+BEGIN_SRC clojure :depify {:extra-deps {org.clojure/clojure {:mvn/version "1.9.0"} depify {:git/url "https://github.com/hagmonk/depify" :sha "04329744872890711dbba8939a16e9987dd33bb3"}} :main-opts ["-m" "depify.project"]} :zprint {:extra-deps {org.clojure/clojure {:mvn/version "1.9.0"} zprint {:mvn/version "0.4.9"}} :main-opts ["-m" "zprint.main"]} #+END_SRC

Then, invoke depify in any folder that contains a project.clj:

#+BEGIN_SRC sh clj -A:depify #+END_SRC

depify will read any pre-existing deps.edn file in your project folder and use that as an initial starting point. The result of merging project.clj into deps.edn will be printed to standard out.

depify can also read project.clj files from stdin. This can be handy if, for instance, you want to import a pile of dependencies into your current deps.edn from a remote project.clj:

#+BEGIN_SRC sh curl -L -o - "https://raw.githubusercontent.com/metasoarous/oz/master/project.clj" | clj -A:depify #+END_SRC

depify can also interpret the output from [[https://github.com/technomancy/leiningen/tree/master/lein-pprint][lein pprint]]. This has the advantage of evaluating content inside project.clj - for instance, quoted variables are expanded, paths are resolved, etc.

#+BEGIN_SRC sh lein pprint | clj -A:depify #+END_SRC

lein pprint can be invoked with a list of keys in order to extract specific values from the project.clj data. depify can handle any key that returns a list of maven coordinates, which will be interpreted as simple dependencies. The following will result in a dependency set that is the union of both keys:

#+BEGIN_SRC sh lein pprint :dependencies :plugins | clj -A:depify #+END_SRC

Notice in my ~/.clojure/deps.edn I also have [[https://github.com/kkinnear/zprint][zprint]] as an alias, enabling this from your project folder:

#+BEGIN_SRC sh clj -A:depify | clj -A:zprint > deps.edn.tmp ; mv deps.edn.tmp deps.edn #+END_SRC

You may see a "Stream closed" exception emitted by zprint, which can be safely ignored.

*** Features

Based on the initial concept in [[https://gist.github.com/swlkr/3f346c66410e5c60c59530c4413a248e][this gist]] by [[https://github.com/swlkr][Sean Walker]]. depify improves on it slightly:

**** Adds entries to the existing deps.edn, if available

deps.edn

#+BEGIN_SRC clojure {:deps {ding/dong {:mvn/version "1.0"}}} #+END_SRC

project.clj

#+BEGIN_SRC clojure (defproject super-dooper "1.0" :dependencies [[tick/tock "1.0"]]) #+END_SRC

deps.edn

#+BEGIN_SRC clojure {:deps {ding/dong {:mvn/version "1.0"}, tick/tock {:mvn/version "1.0"}}} #+END_SRC

**** Handles variable unquoting in project.clj

project.clj

#+BEGIN_SRC clojure (def something "0.1.2") (defproject foobar "1.0" :dependencies [[something/gizmo ~something]]) #+END_SRC

deps.edn

#+BEGIN_SRC clojure {:deps {something/gizmo {:mvn/version "0.1.2"}}} #+END_SRC

**** Places lein's :main and :jvm-opts under an alias called :run

project.clj

#+BEGIN_SRC clojure (defproject super-dooper "1.0" :jvm-opts ["-XX:+EnormousBiceps"] :main super-dooper.core :dependencies [[ding/dong "1.0"]]) #+END_SRC

deps.edn

#+BEGIN_SRC clojure {:aliases {:run {:jvm-opts ["-XX:+EnormousBiceps"], :main-opts ["-m" "super-dooper.core"]}}, :deps {ding/dong {:mvn/version "1.0"}}} #+END_SRC

**** Creates aliases for any :profiles

project.clj

#+BEGIN_SRC clojure (defproject super-dooper "1.0" :jvm-opts ["-XX:+EnormousBiceps"] :main super-dooper.core :dependencies [[ding/dong "1.0"]] :profiles {:dev {:dependencies [[tick/tock "1.0"]] :jvm-opts ["-XX:+CrashAndBurn"]}}) #+END_SRC

deps.edn

#+BEGIN_SRC clojure {:aliases {:run {:jvm-opts ["-XX:+EnormousBiceps"], :main-opts ["-m" "super-dooper.core"]}, :dev {:jvm-opts ["-XX:+CrashAndBurn"], :extra-deps {tick/tock {:mvn/version "1.0"}}}}, :deps {ding/dong {:mvn/version "1.0"}}} #+END_SRC

**** Adds :test-paths to the :test alias

project.clj

#+BEGIN_SRC clojure (defproject super-dooper "1.0" :dependencies [[ding/dong "1.0"]] :test-paths ["testomatic"]) #+END_SRC

deps.edn

#+BEGIN_SRC clojure {:aliases {:test {:extra-paths ["test" "testomatic"], :extra-deps {org.clojure/test.check {:mvn/version "RELEASE"}}}, :runner {:extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner", :sha "76568540e7f40268ad2b646110f237a60295fa3c"}}, :main-opts ["-m" "cognitect.test-runner" "-d" "test"]}}, :deps {ding/dong {:mvn/version "1.0"}}} #+END_SRC

**** Adds :source-paths and :resource-paths to :paths

project.clj

#+BEGIN_SRC clojure (defproject super-dooper "1.0" :dependencies [[ding/dong "1.0"]] :resource-paths ["more-resources"] :source-paths ["more-sources"]) #+END_SRC

deps.edn

#+BEGIN_SRC clojure {:deps {ding/dong {:mvn/version "1.0"}}, :paths ["src" "more-sources" "more-resources"]} #+END_SRC

**** Adds :respositories to :mvn/repos

project.clj

#+BEGIN_SRC clojure (defproject super-dooper "1.0" :dependencies [[ding/dong "1.0"]] :repositories [["java.net" "https://download.java.net/maven/2"] ["releases" {:url "https://blueant.com/archiva/internal" :username "milgrim", :password :env}]])

#+END_SRC

deps.edn

#+BEGIN_SRC clojure {:deps {ding/dong {:mvn/version "1.0"}}, :mvn/repos {"java.net" {:url "https://download.java.net/maven/2"}, "releases" {:url "https://blueant.com/archiva/internal"}}}

#+END_SRC

*** Testing

Tests can be invoked with:

#+BEGIN_SRC sh clj -A:test #+END_SRC