Clojure, Software Design, Frameworks and more...

Boot Localrepo?

Sometimes you just can’t help having a “random 3rd part JAR file” in your project. The best practice is, of course, to upload it to your preferred Maven-compatible repository via whatever service or software you use for all your in-house shared artifacts. But sometimes you just want to play with that JAR file locally, or you haven’t gotten around to running your own shared repository.

If you’re using Leiningen, you’ll probably reach for the excellent lein-localrepo which lets you “install” your random JAR file into your local Maven cache (in ~/.m2/repository).

What do you do if you’re using Boot instead?

Well, you could just keep lein installed and use it for this (with the lein-localrepo plugin dependency in your ~/.lein/profiles.clj, for example):

What the what? Yeah, that’s really kind of ugly. Unfortunately, the install task seems to expect a physical pom.xml file when you specify a physical JAR file. That means we need to drop a target task into the pipeline into order for the generated pom.xml to be written to disk. It would be nice if it would look in the fileset first, because then at least this should work:

Well, it turns out that you can run some Leiningen plugins directly from Boot, from the command line! Boot lets you specify dependencies on the command line, and it lets you “call” Clojure code from the command line too. Let’s start a REPL with lein-localrepo as a dependency:

1

boot -d leiningen -d lein-localrepo repl

We need Leiningen as well since plugins rely on it as a dependency. Now, in the REPL we can require the main namespace from the plugin, and get information about the entry point:

For any given plugin, lein-foo, the entry point is leiningen.foo/foo. Note that it is called with an unused argument and then the actual command line arguments. So we can ask for help on the install command:

Oh, that’s a bit disappointing – we exited the REPL and got our command prompt back. I guess that calls (System/exit) which is a bit unfriendly (but, perhaps, not unexpected given the use case for this plugin). But we can verify that the JAR file was installed:

Now, remember that I said you can “call” code from the command line with Boot? Since we know the code we need to execute (the require and the call to lr/localrepo), we’ll just supply those as command line arguments to the call task: