Oct 302011

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
  2. 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
  3. Add the following to project.clj

    :repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}
  4. 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.

  19 Responses to “Using local jars with leiningen”

  1. [...] manages our dependencies and packages our jars. We’ve found it helpful to set up a local maven repository in our vendor directory for a couple of cases where we needed a jar that was neither in the main [...]

  2. [...] Paul Gross has written a cool blog post explaining how his team got past this [...]

  3. Found link to this post via Mark Needham’s blog-post. The problems I notice are:
    1. User needs to have Maven installed
    2. Dealing with “maven_repository” folder may be unnecessary

    Just wanted to suggest using `lein-localrepo` (URL below) after installing as a plugin:


    • It looks like each person has to use lein-localrepo to install the jars into their own maven repository. What I wanted was something simpler, where every user of the project can merely run:

      git clone ...
      lein deps
      lein run

      The work is done upfront to get the maven repository in the project, but then others do not have to worry about it.

  4. [...] got the JOGL libraries from here and here.  I packaged the libraries up for leiningen using this.  The only trick after that was ripping out all the other jar signatures and making sure they all [...]

  5. Thanks a lot, works like a charm. Can also be pushed to heroku.

  6. awesome, thanks. you can also add -DcreateChecksum=true to the install-file to generate a checksum and suppress some warnings from lein.

  7. [...] turns out that it’s not terribly difficult to create a local Maven repository. I followed the steps that I found on Paul Gross’s blog, adding -DcreateChecksum=true as suggested in the comments, to create a repository containing [...]

  8. You saved me days of heartache, PG! Thanks.

  9. Thanks for the hint!

    Leiningen 2.0 (2.0-preview6, to be precise) fails when it is unable to verify the checksum, though. This can be fixed by adding -DcreateChecksum=true to the mvn install line.

    • Thank you very much for that comment.
      Made my day!

      • Yes, thanks, that comment saved my day as well. Lein deps gave me no indication of why it was failing to find the jar …..like “Found file, but there is no checksum, please created one!” would have been useful.

  10. I couldn’t get this too work with the latest Leiningen version, but with this gist the trick did work: https://gist.github.com/3062743

    Thanks for the post,

  11. [...] WordCram and other needed libraries are not in any public ones. I’d followed the instructions on this post from late 2011. I had since upgraded to leiningen 2.1.3, for which this recipe doesn’t work anymore. The [...]

  12. I can’t solve this in Lein preview 2.10. So I found another solution like below:

    1. Use deploy to replace install
    mvn deploy:deploy-file -Dfile=jnotify-0.94.jar -DartifactId=jnotify -Dversion=0.94 -DgroupId=jnotify -Dpackaging=jar -Durl=file:/home/xxx/maven_repository/

    Add repo to project.clj
    :repositories {“local” “file:/home/xxx/maven_repository”}

  13. looking at the source for project.clj, the code has been changed to:

    :repositories {“local” “file:repo”}

  14. I installed a jar file to my user-local Maven cache (e.g. /home/jeff/.m2) with the following:

    mvn install:install-file -DgeneratePom=true -DcreateChecksum=true \
    -Dpackaging=jar -Dfile=db2jcc4.jar -DgroupId=com.ibm.db2.jcc \
    -DartifactId=db2jcc4 -Dversion=4.18.60

    and then I was able to include the jar as a dependency in my project.clj the usual way:

    [com.ibm.db2.jcc/db2jcc4 "4.18.60"]

    I’m not sure how this would work for deployment, but lein does include the dependent classes in an uberjar.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">