Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'file:' repositories in Leiningen 2.0.0-preview5 and later

Sample Project

Starting from:

lein new foo
cd foo

Say I have a random JAR file that is not available in any repository:

touch README.md
jar cf bar.jar README.md

Let's assume I've installed it in a project-local repository like this:

mkdir repo
mvn install:install-file -DgroupId=local -DartifactId=bar \
    -Dversion=1.0.0 -Dpackaging=jar -Dfile=bar.jar \
    -DlocalRepositoryPath=repo

And I write my project.clj like this:

(defproject foo "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [local/bar "1.0.0"]]
  :repositories {"project" "file:repo"})

With Lein 2.0.0-preview4

Making sure my local cache is clean:

$ rm -rf ~/.m2/repository/local

The first time, Leiningen prints errors:

$ lein deps
Could not find artifact local:bar:pom:1.0.0 in central (http://repo1.maven.org/maven2)
Could not find artifact local:bar:pom:1.0.0 in clojars (http://clojars.org/repo/)
Retrieving local/bar/1.0.0/bar-1.0.0.pom (1k)from file:repo/
no supported algorithms found
Could not find artifact local:bar:jar:1.0.0 in central (http://repo1.maven.org/maven2)
Could not find artifact local:bar:jar:1.0.0 in clojars (http://clojars.org/repo/)
Retrieving local/bar/1.0.0/bar-1.0.0.jar (1k)from file:repo/
no supported algorithms found

But the second time it works:

$ lein deps
$ 

Some inspection shows that local/bar has been copied to my ~/.m2/repository cache:

$ find ~/.m2/repository/local
~/.m2/repository/local
~/.m2/repository/local/bar
~/.m2/repository/local/bar/1.0.0
~/.m2/repository/local/bar/1.0.0/_maven.repositories
~/.m2/repository/local/bar/1.0.0/bar-1.0.0.jar
~/.m2/repository/local/bar/1.0.0/bar-1.0.0.pom

With Lein 2.0.0-preview5 through preview7

Starting from scratch:

$ rm -rf ~/.m2/repository/local

Try running Leiningen:

$ lein deps
Could not find artifact local:bar:pom:1.0.0 in central (http://repo1.maven.org/maven2)
Could not find artifact local:bar:pom:1.0.0 in clojars (https://clojars.org/repo/)
Retrieving local/bar/1.0.0/bar-1.0.0.pom (1k)from file:repo/
Could not transfer artifact local:bar:pom:1.0.0 from/to project (file:repo): no supported algorithms found
Failed to collect dependencies for [#<Dependency org.clojure:clojure:jar:1.4.0 (compile)> #<Dependency local:bar:jar:1.0.0 (compile)>]

No matter how many times I run it, I get the same results. My ~/.m2/repository cache has the correct directories, but no files have been copied:

$ find ~/.m2/repository/local
~/.m2/repository/local
~/.m2/repository/local/bar
~/.m2/repository/local/bar/1.0.0

The Repository URL

Variations on the repository URL like file://repo have no positive effect.

@stuartsierra

This comment has been minimized.

Show comment
Hide comment
@stuartsierra

stuartsierra Jul 7, 2012

The solution, courtesy of Nelson Morris, is to use mvn deploy:deploy-file instead of install:install-file, and to specify -Durl=file:repo instead of -DlocalRepositoryPath=repo.

The final command looks like this:

mvn deploy:deploy-file -DgroupId=local -DartifactId=bar \
  -Dversion=1.0.0 -Dpackaging=jar -Dfile=bar.jar \
  -Durl=file:repo

This tells Maven to create the checksums and additional metadata that is expected from a real repository, which makes Leiningen's dependency resolution work again.

Here's the mailing list discussion.

Owner

stuartsierra commented Jul 7, 2012

The solution, courtesy of Nelson Morris, is to use mvn deploy:deploy-file instead of install:install-file, and to specify -Durl=file:repo instead of -DlocalRepositoryPath=repo.

The final command looks like this:

mvn deploy:deploy-file -DgroupId=local -DartifactId=bar \
  -Dversion=1.0.0 -Dpackaging=jar -Dfile=bar.jar \
  -Durl=file:repo

This tells Maven to create the checksums and additional metadata that is expected from a real repository, which makes Leiningen's dependency resolution work again.

Here's the mailing list discussion.

@jeroenvandijk

This comment has been minimized.

Show comment
Hide comment
@jeroenvandijk

jeroenvandijk Aug 10, 2012

This works for me! Thanks a lot!

This works for me! Thanks a lot!

@defHLT

This comment has been minimized.

Show comment
Hide comment
@defHLT

defHLT Sep 22, 2013

Thank you. Not being acquired both with maven and lein it took me a day of googling and retrying. Errors are extremely not helpful.

defHLT commented Sep 22, 2013

Thank you. Not being acquired both with maven and lein it took me a day of googling and retrying. Errors are extremely not helpful.

@jfacorro

This comment has been minimized.

Show comment
Hide comment
@jfacorro

jfacorro Oct 6, 2013

@liverlin Same here :)

jfacorro commented Oct 6, 2013

@liverlin Same here :)

@escheffel

This comment has been minimized.

Show comment
Hide comment
@escheffel

escheffel Apr 25, 2014

Hi there,

How does the above method (deploy:deploy-file) work when I want to copy a JAR file into a local maven repo which possesses as a dependency a local JNI-created dynamically linked library in some native language such as C? The two files "file1.jar" and "file1.so" always have to be deployed jointly. Thanks for any help!

Hi there,

How does the above method (deploy:deploy-file) work when I want to copy a JAR file into a local maven repo which possesses as a dependency a local JNI-created dynamically linked library in some native language such as C? The two files "file1.jar" and "file1.so" always have to be deployed jointly. Thanks for any help!

@IvanDyachenko

This comment has been minimized.

Show comment
Hide comment
@IvanDyachenko

IvanDyachenko Nov 14, 2014

Thanks for solution!

Thanks for solution!

@aaronblenkush

This comment has been minimized.

Show comment
Hide comment
@aaronblenkush

aaronblenkush Nov 10, 2015

To get the Lein 2 equivalent of @stuartsierra's command above without using Maven:

Add to project.clj:

:repositories [["project" {:url "file:repo" username "" :password ""}]]

Run lein deploy [repo] [artifact] [version] [jar-path]

lein deploy project local/bar 1.0.0 bar.jar

Then you can add the dependency to project.clj as:

[local/bar "1.0.0"]

To get the Lein 2 equivalent of @stuartsierra's command above without using Maven:

Add to project.clj:

:repositories [["project" {:url "file:repo" username "" :password ""}]]

Run lein deploy [repo] [artifact] [version] [jar-path]

lein deploy project local/bar 1.0.0 bar.jar

Then you can add the dependency to project.clj as:

[local/bar "1.0.0"]
@coxchen

This comment has been minimized.

Show comment
Hide comment

coxchen commented Dec 3, 2015

@aaronblenkush thanks a lot!!!

@zot

This comment has been minimized.

Show comment
Hide comment
@zot

zot Sep 20, 2016

Thanks, this worked for me!

zot commented Sep 20, 2016

Thanks, this worked for me!

@benwhorwood

This comment has been minimized.

Show comment
Hide comment
@benwhorwood

benwhorwood Jan 19, 2017

Thanks @aaronblenkush, worked for me to get a third party JDBC driver added to a project and available on the class path ((:import works as well as specifying class for java.jdbc connection).

Thanks @aaronblenkush, worked for me to get a third party JDBC driver added to a project and available on the class path ((:import works as well as specifying class for java.jdbc connection).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment