Skip to content

Instantly share code, notes, and snippets.

@techwhizbang
Created February 8, 2014 18:30
Show Gist options
  • Save techwhizbang/8887976 to your computer and use it in GitHub Desktop.
Save techwhizbang/8887976 to your computer and use it in GitHub Desktop.
Difficulty reading environment variables in Leiningen project.clj
; consider this example
(let [_ (prn (System/getenv))]
(defproject your-clojure-app "1.0.0-SNAPSHOT"
:mirrors {#".+" {:url "https://internal.artifactory.repo.com/repo"
:username :env/artifactory_username
:password :env/artifactory_password}}))
; in the above example I confirm that the environment variables that I want
; namely "artifactory_username" and "artifactory_password" are present, however
; they are NOT picked up using the Leiningen :env/artifactory_username :env/artifactory_password
; syntax
; consider this variant b/c maybe it's something simple like typecase sensitivity
(let [_ (prn (System/getenv))]
(defproject your-clojure-app "1.0.0-SNAPSHOT"
:mirrors {#".+" {:url "https://internal.artifactory.repo.com/repo"
:username :env/ARTIFACTORY_USERNAME
:password :env/ARTIFACTORY_PASSWORD}}))
; again the environment variables are present based on the
; the stdout of (System/getenv) but yet the :env/ARTIFACTORY_USERNAME
; and :env/ARTIFACTORY_PASSWORD yield nil
; in a last ditch effort to use environment variables
(let [_ (prn (System/getenv))
artifactory_username (System/getenv "artifactory_username")
artifactory_password (System/getenv "artifactory_password")]
(defproject your-clojure-app "1.0.0-SNAPSHOT"
:mirrors {#".+" {:url "https://internal.artifactory.repo.com/repo"
:username ~artifactory_username
:password ~artifactory_password}}))
; the above example works and I then successfully authenticate to my private mirror
; and pull down my dependencies
; what am I doing wrong with :env/ARTIFACTORY_USERNAME and :env/ARTIFACTORY_PASSWORD
; that they aren't yielding the correct result?
@LusciousPear
Copy link

Did you ever find a resolution for this? I just had to do the same.

@RobinNagpal
Copy link

OK, it was a case of reading the docs more thoroughly. :) To access environment variables specified in the project map you need the lein-environ plugin. Add it like this:

:plugins [[lein-environ "0.4.0"]]
That worked. It's easy to miss that in the docs though.

@RobinNagpal
Copy link

I just came across this answer. Will give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment