Skip to content

Instantly share code, notes, and snippets.

@postspectacular
Last active October 4, 2020 13:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save postspectacular/6214886 to your computer and use it in GitHub Desktop.
Save postspectacular/6214886 to your computer and use it in GitHub Desktop.
Quick demo project of how to use leiningen profiles to provide alternative implementations of a namespace... The project.clj defines two profiles :dev & :prod with alternative source paths for each. The main code should remain in the main /src folder and the namespace to be altered must be provided in both /src.dev and /src.prod
(defproject profiletest "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]]
:main profiletest.core
:profiles {
:dev {:source-paths ["src" "src.dev"]}
:prod {:source-paths ["src" "src.prod"]}
})
;; the main/shared ns pulling in the correct version of profiletest.foo,
;; based on current lein profile settings
(ns profiletest.core
(:require [profiletest.foo :as foo]))
(defn -main [] (println "active profile " (foo/blah)))
;; src.dev/profiletest/foo.clj
;; implementation of profiletest.foo for :dev profile
(ns profiletest.foo)
(defn blah [] :dev)
;; src.prod/profiletest/foo.clj
;; implementation of profiletest.foo for :prod profile
(ns profiletest.foo)
(defn blah [] :prod)
$ lein with-profile dev run
Performing task 'run' with profile(s): 'dev'
active profile :dev
$ lein with-profile prod run
Performing task 'run' with profile(s): 'prod'
active profile :prod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment