Leiningen: working with local repository

Leiningen is de facto standard for creating and managing projects in Clojure. To create new project we can simply write:

lein new my-app

and a basic structure of the project is created for us. Now to add any dependencies (and download them from Maven or Clojars repository) we need to modify project.clj file. Let say we want to generate markdown from a string, so we need to add markdown-clj project. To do so we need to modify project.clj file in our project:

(defproject my-app "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.6.0"]
                 [markdown-clj "0.9.63"]]
   :main ^:skip-aot my-app.core)

then we can write such code in \my-app\src\my_app\core.clj file:

(ns my-app.core
  (:require [markdown.core :as mark]))

(defn -main []
   (mark/md-to-html-string "#Header")))

Everything works great! But now for unknown reason, temporary, we want to modify md-to-html-string function (from markdown-clj/src/markdown/core.clj), to convert all our text to upper case. Figuring out how to do that can take a while (at least for me it wasn’t so intuitive how to change depended code), so I will show you.

First we need to clone git repository to local disk.

git clone https://github.com/yogthos/markdown-clj.git

Then we can modify md-to-html-string function in core.clj file:

(defn md-to-html-string
  "converts a markdown formatted string to an HTML formatted string"
  [text & params]
  (when text
    (let [input (new StringReader text)
          output (new StringWriter)]
      (apply (partial md-to-html input output) params)
       (.toString output)))))

and change a version name in project.clj file - to not interfere with the original one:

(defproject markdown-clj "0.9.63-SNAPSHOT"
            :description "Markdown parser"
            :url "https://github.com/yogthos/markdown-clj"
            :license {:name "Eclipse Public License"
                      :url "http://www.eclipse.org/legal/epl-v10.html"}
                      :dependencies [[org.clojure/clojure "1.6.0"]]

and the last (but most important part) is to install this library in our local Clojure repository. To do that we need to be in markdown-clj project directory (where the project.clj file is) and write:

lein install

This will install jar and pom of markdown-clj project, in version 0.9.63-SNAPSHOT into local repo. We can use it now, by simply specifing correct version in our project.clj file:

(defproject my-app "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.6.0"]
                 [markdown-clj "0.9.63-SNAPSHOT"]]
				 :main ^:skip-aot my-app.core)

After this the modified version of markdown-clj project will be used. When we execute this code:

(mark/md-to-html-string "#Header")

we will get:


This can be useful if you need temporary fix a bug or test your future pull request.

You may also like

ClojureScript: JavaScript Interop

Lesser known Clojure: variants of threading macro

Template method pattern