Can you have leiningen load library code from locally checked out source?
Asked Answered
D

1

14

Let's say I was hacking on a clojure library I was using in my project:

/User/SCdF/Code/myproject/
/User/SCdF/Code/other-peoples-projects/clojure-library-cloned-from-github

Currently, when I make changes in clojure-library-cloned-from-github I then run lein install to push my new version to the local repository (I've changed my and their project.clj to point to a newer -SNAPSHOT version of the library so it gets updated every time) and then restart / run lein deps on myproject.

Is there a way I can tell leiningen to look in ../../clojure-library-cloned-from-github for the source code for the library instead of using a maven and jars, so that when I make changes to the code they're seen at runtime?

Deidradeidre answered 25/7, 2013 at 2:34 Comment(0)
H
19

Check out Leiningens checkout dependencies functionality.

Basically, you make a symbolic link to the library directory in a subdirectory called 'checkouts' of your current project, and add it to your Leiningen profile. Now that project is loaded too whenever your program is started from Leiningen (REPL, run).

If you are on Windows, instead of making a symbolic link, you need to make the NTFS equivalent of a symbolic link to a directory, called a 'junction point'.

Take care that this does not work if your project isn't actually started through Leiningen (for instance in Eclipse/CounterClockWise). If you run from CounterClockWise, you need to add the library you want as an Eclipse project, then edit the Eclipse project properties of your own project: Under Java Build Path > Projects, add the library project.

Now if you start from the Eclipse REPL, the library will be included to the java class path. However, if you want the project to work when run through Leiningen as well, you also need to use the checkouts functionality.

Of course, whenever you want to make a standalone build of your program, the checkouts way won't work anymore, and you need to include the library as a normal dependency, or include a built version in your uberjar.

Hutchinson answered 25/7, 2013 at 11:6 Comment(2)
Side question, wouldn't that confuse git? On 'nix I imagine it knows about soft links and you can tell it not to follow them, but aren't junction points on NTFS basically transparent? I suppose you add checkouts/ to .gitignoreDeidradeidre
Yes, checkouts is a local develop only functionality. That's why you need to actually add the library in your project dependencies as well, the checkout version just gets preferred over it. So ignoring it in your versioning is a good idea.Hutchinson

© 2022 - 2024 — McMap. All rights reserved.