Last active
October 4, 2020 13:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"]} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; src.dev/profiletest/foo.clj | |
;; implementation of profiletest.foo for :dev profile | |
(ns profiletest.foo) | |
(defn blah [] :dev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; src.prod/profiletest/foo.clj | |
;; implementation of profiletest.foo for :prod profile | |
(ns profiletest.foo) | |
(defn blah [] :prod) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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