Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Leiningen to use a corporate repository?

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?

like image 480
Olaf Avatar asked Mar 28 '14 15:03

Olaf


2 Answers

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.

like image 84
Josh Glover Avatar answered Nov 16 '22 04:11

Josh Glover


As far as I can see in Leiningen's example project.clj you have to use the name of the repository to mirror as the key in the :mirrors map. So, try this:

{:mirrors {"central" { ... }}}

This will most likely replace the repository completely, so you might want to add the original again:

{:mirrors      {"central" {:url "..." }}
 :repositories {"maven"   {:url "http://repo1.maven.org/maven2/"}}}
like image 22
xsc Avatar answered Nov 16 '22 03:11

xsc