Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leiningen: How to define constants in project.clj?

I have some values repeated in my project.clj like below:

(defproject foo "0.1.0-SNAPSHOT"
  ...

  :dependencies [[bar "3.4.5"]
                 [baz "3.4.5"]
                 [bat "3.4.5"]]

  ...)

I would like to use some sort of constant here so, when these libraries get updated to 3.5.0 for example, I have to change just one place.

What is the best practise here? Best I can come up with is this:

(def deps-version "3.4.5")

(defproject foo "0.1.0-SNAPSHOT"
  ...

  :dependencies [[bar ~deps-version]
                 [baz ~deps-version]
                 [bat ~deps-version]]

  ...)
like image 954
muhuk Avatar asked Jun 29 '15 11:06

muhuk


1 Answers

Using a definition before defproject is totally fine and common practice.

You can also so more advanced stuff like depending on the build environment (I would tag the effective project version too that case). A nice example is found in the answers to this question "Leiningen: How to define constants in project.clj?"

like image 138
ordnungswidrig Avatar answered Sep 18 '22 00:09

ordnungswidrig