Started playing with the Leiningen build system for Clojure today. It is suppose to be a cleaner simpler version of Maven/Gradle.
At this point, it was not difficult to setup. I had to start with the following actions:
- Download the Lein installation script. The script can be downloaded off of the Leiningen (now referred to as Lein) website at this link.
- After I downloaded the script, I setup up my PATH directory (I am using OS X) to point to the directory where I have lein installed and ran:
- This kicked off the installation process. All files were installed in the self-installed directory.
- Once everything installed, I was able to start my first Clojure project. I am currently working on a simple project, I call cvssplitter. This is a test project to kick the tires on Clojure and better understand the LISP programming model. To get started with my project, I issued the following command:
lein new cvssplitter
- This creates a new directory structure for me with the following directories and files created for me:
cvssplitter --> Root directory for my project.
src --> Source directory for all Clojure project files
test --> Test directory for all Clojure test projects
doc --> Directory for all Clojure documentation.
project.clj --> Clojure file that describes the project and its corresponding
target --> Output directory for all compiled class files
- After the project was created, I modified the following the file:
core.clj --> This is the file I modified.
- I added two new functions to the code in the file:
(:require [clojure.java.io :as io]) <-- br="" imported="" library="" the="">)
(defn foo <- br="" by="" generated="" his="" lein="" nbsp="" was=""> "I don't do a whole lot."
(println "Hello, World!" x))->-->
(defn loadfile <-- a="" br="" is="" library="" new="" this=""> [file-name]
(with-open [rdr (io/reader file-name)]
(doseq [line (line-seq rdr)]
(defn -main (foo "Sean")) <-- a="" added="" blockquote="" main="" method="">
8. Once the code was completed, I loaded a repl via lein:
9. In the repl, I entered the following commands:
(require 'cvssplitter.core)10. The small script then loaded the file and printed out the contents of the file.