How to use leiningen to develop using local jars?
Asked Answered
M

3

10

I realize that this question is pretty much the exact question found here. However, seeing as that question is 1.5 years old (or so), I would like to revisit it. How does one add local dependencies using leiningen? Surely this capability must exist by now?

Moravian answered 7/12, 2011 at 6:46 Comment(0)
S
8

Create a private Maven Repository, and then, add the following to your project.clj

:repositories {"local" ~(str (.toURI (java.io.File. "your_local_repository")))}
Suppletory answered 7/12, 2011 at 6:51 Comment(4)
Great, thanks. Btw, I just did this: :repositories {"local" "/my/string/path"} and it worked just fine.Moravian
But, other developer, who clone your your project need to change the path!Suppletory
Given that leiningen creates a private maven repository when it starts, what is wrong with installing (lein install) the jar file to the same private repository?Momently
Leiningen plugin localrepo makes the task of adding jars to a local maven repo that much easier: #8739164Autopilot
C
7

If the jars are based on your own projects, you can use lein install to put them into your local .m2, or use the checkout-dependencies feature.

You can also use the extra-classpaths feature, etc.

Cattery answered 8/12, 2011 at 18:57 Comment(0)
M
2

I found that the easiest (albeit somewhat hacky) solution is to do the following:

For an existing project that you're using as a dependency:

  1. In your local project that has the dependency you want to modify, ensure you run lein deps
  2. Clone the repo of this dependency so you can modify it locally (obv. make sure you're using the same tag as the version you specify in your project.clj file)
  3. Run lein uberjar in this dependency dir (where the relevant project.clj file lives)
  4. Copy the generated standalone jar in target/ to the exact path/file of your local maven files... (something like: ~/.m2/repository/project/.../file.jar); Ensure that you backup the original jar file so you can restore it later on if that is desirable

For development of your own project:

  1. Within the project or plugin you're developing, simply run lein install
  2. Find out where your local maven repo is (see above for an example path)
  3. Enter dependency information in your test project like you would for any other leiningen project

Again, this is a quick hack and perhaps not the way you'd go about doing serious local development, but I found it easy enough for what I wanted. Check out lein help tutorial for much more info

Millham answered 6/7, 2013 at 14:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.