Clojure is great and it has ton of features that allow developers to increase productivity. With this post we intend to show how to configure clojure to use a repository manager as proxy and how to setup the clojure project to deploy JAR files for shared usage.

Preparation (repository manager setup)

For this tutorial we are going to assume that the Nexus OSS 3 corporate repository manager is configured similar to this:

  1. Anonymous browsing disabled.
  2. The repository configured as a repository proxy. image

  3. Add the Clojars repository to the maven public group repository. image

  4. Add any extra maven repository that is needed in the same way.

Local setup ~/.lein/profiles.clj

  {:mirrors {#".+" {:url "https://my.local.repo/repository/maven-public/"
                    :username :env :password :env }}}}
  • The line {:mirrors {#".+" {:url "https://my.local.repo/repository/maven-public/" tells leiningen to send any request to a repository that matches ".+" to the maven public group repository.

  • The line :username :env :password :env makes leingigen use the environment variables LEIN_USERNAME and LEIN_PASSWORD as authentication credentials.

Project setup lib-tools/project.clj

  • Lastly, add the section deploy-repositories to your project.clj and in order to deploy to the maven repository run lein deploy
(defproject net.spantree/lib-tools "0.0.1-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "Eclipse Public License"
            :url  ""}
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [org.clojure/clojurescript "1.7.145"]
                 [cljs-http "0.1.30" :exclusions
  :deploy-repositories [["releases" {:url "https://my.local.repo/repository/maven-releases/"
                                     :username :env :password :env }]
                        ["snapshots" {:url "https://my.local.repo/repository/maven-snapshots/"
                                      :username :env :password :env}]])
  • The output of the command should look similar to this:
$ lein deploy
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
WARNING: please set :description in project.clj.
WARNING: please set :url in project.clj.
Created /Users/otaeguis/projects/src/lib-tools/target/lib-tools-0.0.1-SNAPSHOT.jar
Wrote /Users/otaeguis/projects/src/lib-tools/pom.xml
Retrieving net.spantree/lib-tools/0.0.1-SNAPSHOT/maven-metadata.xml
    from https://my.local.repo/repository/maven-snapshots/
Sending net.spantree/lib-tools/0.0.1-SNAPSHOT/lib-tools-0.0.1-20160713.062217-13.jar (9k)
    to https://my.local.repo/repository/maven-snapshots/
Sending net.spantree/lib-tools/0.0.1-SNAPSHOT/lib-tools-0.0.1-20160713.062217-13.pom (3k)
    to https://my.local.repo/repository/maven-snapshots/
Retrieving net.spantree/lib-tools/maven-metadata.xml
    from https://my.local.repo/repository/maven-snapshots/
Sending net.spantree/lib-tools/0.0.1-SNAPSHOT/maven-metadata.xml (1k)
    to https://my.local.repo/repository/maven-snapshots/
Sending net.spantree/lib-tools/maven-metadata.xml (1k)
    to https://my.local.repo/repository/maven-snapshots/