Dependencies in maven local repositories with lein

2019-02-03 17:44发布

问题:

I am starting lein new project in clojure and want to use the goose article extraction library. Unfortunately I couldn't find the jar of that library on any publicly available maven repository, so I set out to add it to a local maven repository.

In the project directory, I copied the goose jar and its pom.xml files and did

mkdir maven-repo
mvn install:install-file -Dfile=goose-2.1.6.jar -DartifactId=goose -Dversion=2.1.6 \
    -DgroupId=local -Dpackaging=jar -DlocalRepositoryPath=maven-repo -DpomFile=pom.xml

And added the following to project.clj

:repositories {"local" ~(str (.toURI (java.io.File. "maven-repo")))}

and [local/goose "2.1.6"] in :dependencies. Now when I do a lein deps, I get the goose-2.1.6.jar file added to lib directory, but not the dependencies of goose. They are listed in the goose's pom.xml file.

Is there a way I can fix this other than listing goose's dependencies in my project.clj?

回答1:

You can use lein-localrepo instead of the lengthy mvn command: https://github.com/kumarshantanu/lein-localrepo

Install like this:

lein localrepo coords target/goose-2.1.6.jar | xargs lein localrepo install

However, that alone will not help to install the POM file in the repo. You should additionally run this:

cp pom.xml ~/.m2/repository/goose/goose/2.1.6/goose-2.1.6.pom

Note that in this example Goose will be installed as groupId=goose, artifactId=goose. You can override that if you wish, and probably you should.