How to configure Leiningen to use a corporate repository?
Asked Answered
G

2

13

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?

Galaxy answered 28/3, 2014 at 15:6 Comment(0)
S
5

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.

Sawmill answered 7/5, 2014 at 9:21 Comment(1)
Oops, looks like I need the mirrors bit. I had a dependency installed in my local Maven repo that was hiding a problem. Will update my answer momentarily.Sawmill
C
2

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/"}}}
Circularize answered 29/3, 2014 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.