clojure and leiningen - using a git repository as dependency
Asked Answered
T

4

39

Is it possible to have leiningen pull a project directly from a git repository (on github) as a dependency?

Using Bundler with Ruby, it is possible to map a gem to a git repo, allowing for rapid development and integration of dependent projects.

Update

Based on the accepted answer, there is now a leiningen plugin for managing git-deps: https://github.com/tobyhede/lein-git-deps

Trillbee answered 29/1, 2012 at 6:56 Comment(0)
B
5

Answer for 2017: Use lein-voom

You can use lein-voom to pull and build project dependencies from GitHub or other Git repositories. It works by letting you annotate your dependence vector-pair entries with voom-specific meta data. Here's an example from the README:

^{:voom {:repo "https://github.com/ring-clojure/ring" :branch "1.3"}}
[ring/ring-core "1.3.0-RC1-20140519_142204-gaf0379b"]

The main use case given for voom is allowing teams that maintain multiple Clojure projects in separate Git repositories to easily depend on the current version of one or more of the projects from another without having to constantly deploy development snapshot releases.

I prefer lein-voom over lein-git-deps (the plugin recommended in the previously-accepted answer from 2012) for a few reasons:

  1. The fact that the specification is given through meta-data makes this plugin more flexible and easily extensible. It already has an option for specifying a specific branch/tag of the repository. You could add other key/value pairs to the map for additional fine-grained control without too much work.

  2. You can simply delete the meta-data from your dependence entry for stable releases; i.e., there's no need to move entries around / refactor your project.clj once your dependence moves from GitHub into Clojars.

  3. At the time of writing (November 2017), lein-voom has been updated in the past couple of months, whereas lein-git-deps has been stagnant for 4 years.

Bossy answered 25/11, 2017 at 5:10 Comment(0)
S
23

I just found this in clojurescriptone's project.clj

I think it maybe helpful to you:

:git-dependencies [["https://github.com/clojure/clojurescript.git"
                       "886d8dc81812962d30a741d6d05ce9d90975160f"]
                   ["https://github.com/levand/domina.git"
                       "8933b2d12c44832c9bfaecf457a1bc5db251a774"]]

The file is here.

Stoneman answered 29/1, 2012 at 8:36 Comment(3)
Cool, +1! Note that this is not built in to Leiningen -- it's handled by a Leiningen plugin distributed as part of the ClojureScript One source tree. That's not to say there's anything wrong with this solution, just that one would have to extract that plugin from cljs one to use it. Perhaps it'll be published separately at some point. (Or maybe it has been already? I never noticed it before, so I'm really not sure...)Firm
Cool, thanks. In the process of extracting that into a lein plugin, but having a couple of issues (my first attempt at a plugin): github.com/tobyhede/lein-git-deps. Will keep you posted and let you know if it works.Trillbee
Note that you still have to keep track of :extra-classpath-dirs to use this. Ideally you would have a plugin that could inspect all the poms of all your dependencies and find the <scm> element, which could automate adding checkout dependencies for those things that are already listed as :dependencies in project.clj. Such a plugin would be very easy to write if you use a lot of git dependencies.Reedbuck
B
10

Leiningen won't do the pulling for you (edit: not out of the box, anyway; following the lead from Sunng's answer leads one to discover that a plugin has been written for this -- see also my comment on that answer; checkout deps remain a good, built-in solution), but you can have checkouts of other projects put on the classpath. This functionality is described in the FAQ section of the README; here's the relevant Q&A:

Q: I want to hack two projects in parallel, but it's annoying to switch between them.
A: If you create a directory called checkouts in your project root and symlink some other project roots into it, Leiningen will allow you to hack on them in parallel. That means changes in the dependency will be visible in the main project without having to go through the whole install/switch-projects/deps/restart-repl cycle, and the copy in checkouts will take precedence over the dependency declared in project.clj. Note that this is not a replacement for listing the project in :dependencies; it simply supplements that for convenience.

Baudelaire answered 29/1, 2012 at 7:30 Comment(0)
B
5

Answer for 2017: Use lein-voom

You can use lein-voom to pull and build project dependencies from GitHub or other Git repositories. It works by letting you annotate your dependence vector-pair entries with voom-specific meta data. Here's an example from the README:

^{:voom {:repo "https://github.com/ring-clojure/ring" :branch "1.3"}}
[ring/ring-core "1.3.0-RC1-20140519_142204-gaf0379b"]

The main use case given for voom is allowing teams that maintain multiple Clojure projects in separate Git repositories to easily depend on the current version of one or more of the projects from another without having to constantly deploy development snapshot releases.

I prefer lein-voom over lein-git-deps (the plugin recommended in the previously-accepted answer from 2012) for a few reasons:

  1. The fact that the specification is given through meta-data makes this plugin more flexible and easily extensible. It already has an option for specifying a specific branch/tag of the repository. You could add other key/value pairs to the map for additional fine-grained control without too much work.

  2. You can simply delete the meta-data from your dependence entry for stable releases; i.e., there's no need to move entries around / refactor your project.clj once your dependence moves from GitHub into Clojars.

  3. At the time of writing (November 2017), lein-voom has been updated in the past couple of months, whereas lein-git-deps has been stagnant for 4 years.

Bossy answered 25/11, 2017 at 5:10 Comment(0)
A
1

I just moved my deps out of Leiningen and into a deps.edn file using lein-tools-deps. You can still use Leiningen as your build tool and use the plugins. But you can pull git dependencies (and all your other dependencies) using deps.edn.

Your project.clj looks something like this:

(defproject example-project "0.1.0-SNAPSHOT"
  :source-paths           [] ;; provided by lein-tools-deps
  :resource-paths         [] ;; provided by lein-tools-deps
  :min-lein-version       "2.0.0"
  :main                   example.core
  :aot                    [example]
  :jar-name               "example.jar"
  :plugins                [[lein-tools-deps "0.4.5"]]
  :middleware             [lein-tools-deps.plugin/resolve-dependencies-with-deps-edn]
  :lein-tools-deps/config {:config-files [:install :project]})

and then your deps.edn is also on the project root and looks something like this:

{:paths ["src" "resources"]
 :deps {org.clojure/clojure    {:mvn/version "1.10.1"}
        org.clojure/data.json  {:mvn/version "1.1.0"}
        github/repo            {:git/url "https://github.com/github/repo.git"
                                :sha "e5f5c9e6839191f1e37ddfa51cf442b2d5403ff3"}}}
Anglia answered 16/3, 2021 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.