Post on 10-May-2015
description
Leiningen 2
Humane build management for
ClojureMadeSimple.co.uk
This slide deck is available to follow along with on slideshare.net
slideshare.net/jr0cket
of Java build management
...there was Ant,Ant begat Ivy,
Ant begat Maven
… and there was much XML all around
build management
Human verses Computer readable build jobs
Leiningen… more fun than Maven
… easy way to kick-start your Clojure addiction
Leiningen: Manual install
Download the Leiningen 2 install script from
leiningen.org
Move the lein file to an executable location, eg.
~/bin
Make the install script executable and run the install
chmod u+x ~/bin/lein
lein
Leiningen: package managers
● Ubuntu● Debian● Fedora● CentOS
Leiningen also staring in
Eclipse plugin Counter Clockwise
All the usual tasks...
lein new
lein deps
lein run
lein jar
● Create a new clojure project
● Download all dependencies
● Run your application
● Deploy your app as a jar
...and then some
lein uberjar
lein repl
jack-in
- Include Clojure & all your dependencies in one jar
- Fire up the dynamic coding environment (REPL)
- Hook to start a REPL from within Emacs
lein replFire up the REPL
REPL: read, evaluate, print loop – dynamic environment for Clojure and other lisps
Typing code into the REPL
Develop functions and data structures on the fly
REPL: read, evaluate, print loop – dynamic environment for Clojure and other lisps
lein new my-projectcd my-projectlein deps
Create a new project
Lein deps will check your project.clj configuration file and download any libraries (jar files) that are required by the project
Anatomy of a new project
Note: dashes in project names are converted to underscores to make Java happy!
Over-riding defaults
lein new template-name my-project
Create project with a different template
Example: WebNoir template
lein new noir fpdays2012-web
cd my-project
git init
Create a repo on github & add it to your project
git remote add origin git@github.com/account/project.git
git push -u origin master
Version your project with Git
You may want to edit your .git-ignore file also
cd my-projectemacs project.clj
Open project in emacs
project.clj - project definition
Lein deps will check this project.clj configuration file and download any libraries (jar files) that are required by the project
Group Dependencies
Usually a reversed domain name
Dev Dependencies
Dev-dependencies: Add libraries only needed for development, not packaged when code deployed
https://clojars.org/
http://search.maven.com
Add a REPL session
REPL: read, evaluate, print, loop – dynamic environment for Clojure and other lisps
Add REPL session to all projects
~/.lein/profiles.clj
M – x clojure-jack-in
Fire up the REPL in Emacs
M – x represents the keyboard combination of the meta key followed by x. Then the command clojure-jack-in is entered.
REPL in Emacs
Add web based REPL
REPL: read, evaluate, print, loop – dynamic environment for Clojure and other lisps
~/.lein/profiles.clj
Leiningen WebRepl plugin
Local Repositories
(just like Maven)
Libraries kept in local .m2 folder
Repositories
https://github.com/technomancy/leiningen/blob/preview/sample.project.clj
Running your project
lein runRuns the main function, or specify main with -m option
Create a new project
lein trampoline run
-m my-app.server 5000
Long running processes
Web applications - noir - enclojure - ring
lein tests
lein tests my.proj.code
lein help tests
Running Tests
Automating test runs ?
Deployment
Jars & Uber Jarslein jar- package up your project,
requires Clojure on the server
lein uberjar- package up everything, even Clojure
project.clj for jar / uberjar
Clojure code for jar / uberjar
Deploy to Clojars
Create a maven pom
lein pom
Create a maven pom
scp pom.xml myproject-0.1.0.jar clojars@clojars.org:
Deploy to Clojars
Or just use lein-clojars
https://github.com/ato/lein-clojars
Deploying to the Cloud
Uses your Leiningen project.clj
- Create your account & install the toolbelt
- Create your instance
- Push your git repo
- Fire up your browser
blog.raynes.me/blog/2011/11/03/moving-try-clojure-to-heroku/
devcenter.heroku.com/articles/clojure-web-application
Leiningen Plug-ins
Running scriptsCopying files
DVCS (git)Continuous
Integration server (Jenkins)
Leiningen.org- Tutorials
- Github Repository- News
- Bug reporting
Choose Life...Choose Life...
… … choose Clojurechoose Clojure
Thank you
@jr0cket
ClojureMadeSimple.co.uk
slideshare.net/jr0cket