1 minute read

Leiningen uses Maven to make dependency management of clojure projects much simpler. However, if you need to depend on jars that are not in a Maven repository, things get a little more complicated.

For example, the Jukebox2 project depends on a bunch of java audio libraries like Jaad that do not live in a Maven repository. We tried checking these jars directly into the lib directory, but leiningen would delete these jars whenever we ran “lein deps.”

The solution we came up with was to make a local Maven repository within the project. Then, anyone can clone the project and run “lein deps” and get all of the dependencies, including the local jars. Here are the steps:

  1. Create a directory in the project
mkdir maven_repository
  1. Add local jars to this repository

For example, this command adds the jaad-0.8.3.jar file to the maven repository.

mvn install:install-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad -Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar -DlocalRepositoryPath=maven_repository
  1. Add the following to project.clj
:repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}
  1. Now a regular lein deps should work
lein deps

Downloading: jaad/jaad/0.8.3/jaad-0.8.3.pom from local
Transferring 0K from local
[WARNING] *** CHECKSUM FAILED - Error retrieving checksum file for jaad/jaad/0.8.3/jaad-0.8.3.pom - IGNORING

The warning can be ignored, since the jar will be checked into the project and not downloaded from the internet.

The final results can be seen in the Jukebox2 project.

Thanks to Matjaz on the Leiningen mailing list for helping me figure out the right syntax for project.clj.

Updated: