How do I use checked-in jars with leiningen
Asked Answered
W

3

16

We have some 3rd-party jars checked-in to our project. We'd like to add them to the classpath. That's it. We don't want to set up a local maven repo (because that would break our 'check out and run' philosophy). Each developer would have to set up their own maven repo, distinct from the project.

Is there a way to do this or is this? Most of the answers I've seen say to set up a local maven which we don't want or need just to add a jar to a classpath.

Wellfounded answered 21/10, 2013 at 13:44 Comment(1)
have you looked at s3-wagon-private? github.com/technomancy/s3-wagon-privateBifoliolate
U
24

You will need to setup a local maven repository, but that can be a simple directory, in your project directory, that you then check in to source control. (Which will maintain your 'check out and run' policy)

As of Leiningen 2.2.0 the functionality to deploy jars is built-in with the lein deploy task. So, the task has simplified from previous versions.

Create a directory inside your project called, in this example, myrepo. (The name is arbitrary)

Add a :repositories entry in your project.clj file with a path to the local directory you created.

:repositories [["localrepo1" "file:myrepo"]]

Deploy your free floating jar to the repo.

lein deploy localrepo1 com.blueant/fancypants 1.0.1 fancypants.jar

And, add your dependency to your project.clj :dependencies vector as normal.

:dependencies [[com.blueant/fancypants "1.0.1"]]

The deploy task will generate the checksums and directory structure required to to tie into the lein dependency resolution. You can verify your jar is loaded correctly with the lein deps :tree command.

Note: File paths in :repositories are formatted as URLs. So, /Users/user1/Desktop is file:///Users/user1/Desktop, and, a local directory within the project, myrepo is file:myrepo.

Uproot answered 21/10, 2013 at 15:25 Comment(2)
See @siphiuel’s answer here for addenda.Fiedling
After doing this, I try, in my core_test.clj, (:require [com.blueant/fancypants "1.0.1"]) and get the dreaded could not locate fancypants__init.class etc when I try lein test. Advice?Unifilar
F
7

I'd like to elaborate on @Jared314's excellent answer that helped me as well.

Below is a script that automates the process of adding multiple jars from a local lib folder to a local repository:

#!/bin/sh
export LOCALREPO_USERNAME=
export LOCALREPO_PASSWORD=

for file in lib/*.jar
do
    name=$(basename "$file")
    basename=${name%.jar}

    echo "Deploying $basename"

    artifactId="local/$basename"
    lein deploy localrepo1 $artifactId 1.0 $file

    echo "[$artifactId \"1.0\"]" >> dependencies.log
done

The list of Leiningen dependencies that can be added to project.clj is stored in dependencies.log.

Before running the script, :repositories entry in project.clj has to be updated to allow for reading repository username and password from the environment:

  :repositories [["localrepo1" {:url "file:myrepo"
                                :username :env/localrepo_username
                                :password :env/localrepo_password}]]

This will prevent the repository password prompt from displaying when running the script.

Fabriane answered 2/11, 2015 at 15:47 Comment(1)
Thanks, this solved the error No credentials found for localrepo1(did you mean `lein deploy clojars`?)Bruno
M
0

This question has already been answered here.

It is indeed possible, but there's a reason why maven and dependency management exists. If you have many dependencies changing versions creating a repo is the recommended approach.

Mislead answered 21/10, 2013 at 14:13 Comment(1)
Please note that answer is over two years old and some of its statements aren't accurate anymore.Bifoliolate

© 2022 - 2024 — McMap. All rights reserved.