How to configure Leiningen to use a corporate repository?

Olaf picture Olaf · Mar 28, 2014 · Viewed 7.7k times · Source

We are hosting a corporate repository which acts as a proxy to the well-known repositories (e.g. Maven Central and Clojars). I want Leiningen to hit the corporate repository in the first place. Only when the corporate repository fails to deliver the artifact Leiningen should ask the standard repositories. This should be the default behaviour of all my projects. What configuration I have to do?

I have added the corporate repository as a mirror in ~/.lein/profiles.clj:

{:user {:mirrors {"our-repo" {:name "our-repo"
                              :url "http://our-repo/all/"}}}}

Unfortunately this setting has no impact. Leiningen downloads the artifacts from Maven Central:

PS> lein repl
Retrieving org/clojure/clojure/1.5.1/clojure-1.5.1.pom from central
...

Update

xsc suggests to overwrite the Maven Central repository with a mirror definition which points to the corporate repository. It works. Now instead of going to the external Maven Repository Leiningen retrieves the artifacts from the corporate repository.

S/He also suggests to specify an additional repository definition to install a fallback mechanism. Unfortunately this does not work so well because Leiningen complains about this setting:

:repositories detected in user-level profiles! [:user]
See https://github.com/technomancy/leiningen/wiki/Repeatability

This warning is very annoying. For this reason I would abstain from this setting. Is there another way to install a fallback mechanism?

Answer

Josh Glover picture Josh Glover · May 7, 2014

Here's what works for me:

{:user {:mirrors {#".+" {:url "http://nexus.example.com:8081/nexus/content/groups/public"}}
        :repositories [["snapshots" {:id "NudaySnapshots"
                                     :url "http://nexus.example.com:8081/nexus/content/repositories/snapshots"}]
                       ["releases" {:id "NudayReleases"
                                    :url "http://nexus.example.com:8081/nexus/content/repositories/releases"
                                    :sign-releases false}]]}
 :auth {:repository-auth {#"nexus.example.com" {:username "deployment"
                                               :password "foo bar baz"}}}}

This handles both resolving dependencies through my Nexus mirror and publishing artifacts to it with lein deploy.

I get the annoying "Repeatability" warning, but I'm working on getting rid of that.