Pass argument to leiningen readable by project.clj
Asked Answered
R

1

5

I have a project.clj file that I want to use differently depending on an argument passed in when called by leiningen. Here is my hypothetical sample project

(defproject simple "0.0.1"
  :source-paths [(get-argument "source.path")])

(In this case get-argument would simply call System/getProperty). I would use this file like this,

lein2 compile -Dsource.path=path/to/location

The problem is two-fold,

  • I don't know how to pass an argument to leiningen. It doesn't accept the -Dkey=value syntax. I couldn't find anything in documentation about passing optional/extra arguments. Am I missing something obvious?
  • The subforms inside defproject seem to be handled a special way. I couldn't find an easy way to put code into it.

I have found some approaches

(What I actually want to use it for is that I have a clojurescript project with different artifacts. While it's possible to configure different builds for it, they all share the same crossovers.)

Rawlings answered 8/4, 2013 at 15:33 Comment(0)
N
11

One approach that is convenient on unix-like platforms is to use an environment variable, combined with lein's willingness to evaluate expressions marked with a tilde in project.clj files. So for your example, you could provide a project.clj like:

(defproject simple "0.0.1"
  :source-paths [~(System/getenv "MY_SRC_PATH")]
  :dependencies [[org.clojure/clojure "1.5.0"]])

...then set the environment variable when launching lein like this:

MY_SRC_PATH="s2" lein compile

I don't know how well this approach would work on Windows.

Nonconformity answered 9/4, 2013 at 5:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.