EzDev.org

leiningen

Automate Clojure projects without setting your hair on fire.


Best practices in building and deploying Clojure applications: good tutorials?

I am new to Clojure, and am beginning to experiment with building an application.

So far, everything I've seen about tutorials on compiling Clojure programs involves interactivity. For example, "load up the REPL and type (load-file "this-or-that") to run. This is fine, but it's not enough.

I am so used to the edit-compile-run idioms of languages like C or Delphi, that I am instinctively driven to make edits, then hit "M-x compile".

The problem is that "lein uberjar", which I understand is the equivalent to "make", is painfully slow to execute even for a hello world. So I'm going to have to figure out how this "interactive development" stuff works, stop using the uberjar like it's quick make, and save it only for the end of the day.

Another thing I noticed while building (using lein uberjar) is that the small GUI app I am working on pops up frames in the compilation process, as if they are executing while compiling. It just seems a bit counterintuitive to me; it is not quite as analogous to "make" as I had thought.

I know the Lisp way of developing things is interactively working in the REPL, and I am not trying to change that: I would like to adapt to this way of life. Unfortunately, I have seen little in the form of documentation on how to do so. For instance, how to reset the current state of the machine. It just seems kind of messy to just keep compiling individual snippets on the fly without being able to do some sort of reset.

Most tutorials I have seen on Clojure (and Lisp) in general seem to focus on hacking in the REPL. Best practices on the deployment of applications remains a mystery to me. My users are just going to be users; they are not going to be developers that are going to load files into a REPL.

So here is my question: any resources for good information or tutorials on the entire process of building a Clojure application, including deployment?

(Note: I have all of the prerequisites installed and working (e.g. Emacs, Slime, Leiningen, etc.), so this is not a question about that).


Source: (StackOverflow)

Java and Clojure with Leiningen

Is it possible to easily manage and compile native Java classes alongside Clojure in a project using leiningen?

I am working at a pretty low level (with netty nio) and thinking that some of the plumbing classes would actually be easier to handle as raw java both in terms of constructing the code as well as performance.


Source: (StackOverflow)

Resources in Clojure applications

I am using Leiningen in my Clojure project (a GUI application) and created a "resources" directory under the project root to hold images that my app uses.

When I am running my app locally during testing, I fetch the images using the relative path "resources/logo.png", and this works fine. But when I build an uberjar using Leiningen, Leiningen puts the files from the resources folder in the JAR's root folder, so my references to resource files don't work anymore.

What is the correct way to access resources like this using Leiningen?


Source: (StackOverflow)

How to upgrade nrepl version of leiningen?

I'm using leiningen and emacs + cider for clojure development. A few days ago, after I upgrade cider through emacs package manager, I'm getting the following warning message when I run M-x cider-connect or M-x cider-jack-in.

; CIDER 0.9.0snapshot (package: 20150222.137) (Java 1.8.0_31, Clojure 1.6.0, nREPL 0.2.6)
WARNING: CIDER requires nREPL 0.2.7 to work properly
user> 

The warning message clearly says that I have to upgrade nrepl to 0.2.7, however, I don't know how.

I installed leiningen via brew, and it uses nrepl 0.2.6.

$ lein repl
nREPL server started on port 53218 on host 127.0.0.1 - nrepl://127.0.0.1:53218
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_31-b13
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=>

The content of leiningen profile is:

{:user {:plugins [[cider/cider-nrepl "0.9.0-SNAPSHOT"]]}}

Question:: How to upgrade the version of nrepl used by leiningen?


Source: (StackOverflow)

How to get Emacs, nrepl.el and Leiningen to play along?

I was actually quite happy with using vim + lein repl, but since so many people keep saying that Emacs is the way to go when it comes to Lisps, I've decided to give it a try. The problem is now setting up a clojure environment that does all the fancy things that people keep talking about - for now I managed to install clojure-mode and nREPL and that works reasonably well, but I need to get the repl to work with my Leiningen projects if this experiment is going to go somewhere (having a repl in the editor would be pretty pointless if that meant having to manage of all my dependencies (especially classpath related ones) on my own again). The problematic point here is that most articles I see online are

  • A) about swank-clojure, which is deprecated
  • B) about Leiningen 1.x, which is deprecated
  • C) both
  • D) Only cover installation, not how to actually use the things you just installed (or even what they do)

Now what I'm looking for is:

  • Get nrepl.el to respect my project.clj
  • Find out what the normal workflow with leiningen + emacs + clojure-mode + nrepl.el is
  • Has nothing to do with the question, but I'd be interested in why emacs sometimes covers up text (changes font color to background color until hit by the cursor) without me asking it to.

Source: (StackOverflow)

"Best Practice" for a clojure library that uses native libs?

While this may appear subjective, there is a concrete example that I'd like help resolving. This is related to an issue with the Overtone Clojure library https://github.com/overtone/overtone/issues/274 which seems like there should be a "Best Practice" for Leiningen and apply to more libraries than just Overtone.

Overtone is a clojure library that is meant to be used from within other projects. Overtone requires native libraries to work, so it uses :native-path "native" in the project.clj https://github.com/overtone/overtone/blob/master/project.clj#L69 in order to get a proper path for the native scsynth libraries [overtone/scsynth "3.5.7.0"] that are used.

However, I believe that this resets the incoming path from a project that depends on the Overtone library. See the issue for some background, but basically after depending on [overtone "0.9.1"] in a project.clj (System/getProperty "java.library.path") returns only the current native path and the project using Overtone cannot pass in a path to any local libraries.

So, the question is--how can a dependent project mix local native libraries with Overtone? Should Overtone or the dependent-project adjust its project.clj settings? How?


Source: (StackOverflow)

clojure lein: How do I include source from another directory in my project?

I have a lein project in one directory, and instead of using the .jar that gets downloaded when I run

> lein deps

I want to use the source from a cloned github repository (It has recent fixes not in the current jar). What is the canonical way to do this with leiningen?

Here is my project file:

(defproject oroboros "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [org.clojure/clojure-contrib "1.2.0"]
                 [clojure-source "1.2.1"]
                 [overtone "0.3.0"]
                 [penumbra "0.6.0-SNAPSHOT"]]
  :native-dependencies [[penumbra/lwjgl "2.4.2"]]
  :dev-dependencies [[native-deps "1.0.5"]
                     [swank-clojure "1.4.0-SNAPSHOT"]])

I want to use the overtone repo from github, rather than the one from clojars.

https://github.com/overtone/overtone

Is this possible?


Source: (StackOverflow)

Standalone clojure app

I'm a beginner with clojure, only starting it yesterday.

I have gathered that a simple way to create a standalone app is with leiningen lein new foo.

I tried to create a hello world test project with leiningen. I added :main and :aot directives to project.clj, added :gen-class to the core.clj file and tried lein run, but I get errors about class definition not found.

Exception in thread "main" java.lang.NoClassDefFoundError: 
Caused by: java.lang.ClassNotFoundException: 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

The core.clj file

(ns test.core
  (:gen-class))
(defn -main [& args] (println "Hello main"))

And the project.clj file

(defproject test "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :main test.core
  :aot [test.core]
  :dependencies [[org.clojure/clojure "1.2.1"]])

Edit: After further testing, it seems like copying the project to my desktop works as is, which I think points to that the environment on my laptop is somehow borked, but I don't know how.

The environment on desktop is clojure from repositories and leiningen from AUR. On laptop the clojure is from clojure.org and leining is from github.


Source: (StackOverflow)

Keeping dependency versions up to date in Leiningen projects

Is there a simple way to find out what versions of dependencies are available using Leiningen?

E.g., if I have a web app which depends on Hiccup and Compojure, how can I be sure that I'm on the latest version of each without going to the github page for each?

NOTE: I use Ant and Ivy for building my Java projects, so I have limited knowledge of Maven - so please spell out (or provide Fine Links for me to read) any Maven concepts that Leiningen exposes to me which would help with this (I know that under the hood, Leiningen uses Maven for dependency resolution). Ta.


Source: (StackOverflow)

How can I set up leiningen to work with multiple projects?

I have multiple, separate leiningen projects that ostensibly could depend on one-another.

Example:

~/projects/mywebapp  (my own project)
~/projects/noir      (a clone of the github repo)
~/projects/clojureql (a clone of the github repo)

I want to have them all compiled into the same JVM at the same time. I would like to run the git repos bleeding edge (pulling new commits/making my own commits) and not have to run lein jar or lein deps and certainly not have to restart the VM if I change any of the projects.

Here's a use case:

After running lein swank, from within emacs, I connect to the repl and compile a file from mywebapp (with C-c-k), which requires a file from noir. It finds the version of the file in my projects directory. Later, I open that file, edit it, and compile it (with C-c-k).

Note that I'm not asking for auto-compiling when I do git pull. I just don't want to have to restart the JVM or do lengthy jar compiling processes.

Is this possible in leiningen? How can I set this up?


Source: (StackOverflow)

How to get runtime access to version number of a running Clojure application?

I have a web service written in Clojure which is continuously delivered. To allow our automated deployment tools to know which version of the codebase has been deployed, the web service should provide a way to query which version it is. The version is declared as part of the project setup in the Leiningen build tool, like this:

(defproject my-web-service "1.2-SNAPSHOT"
  ; ... rest of project.clj
  )

The codebase is packaged as a JAR file.

We developers do not want to increment the version number on each commit. Instead, we want it to be incremented automatically whenever a new build is triggered on our continuous integration server (in this case Jenkins). For example, when a version control checkin prompts the forty-second build of this codebase, the version is 1.2.42.

For any particular JAR that's been built and deployed, I want to allow querying the version number somehow (e.g. with an HTTP request, but that's an implementation detail). The response should include the string 1.2.42.

How do I make that version number available to the running application?

(Possible duplicate, though it doesn't include the Jenkins aspect: Embed version string from leiningen project in application)


Source: (StackOverflow)

Improving startup time of Clojure REPL with Leiningen on the Raspberry Pi

I got a Rasperry Pi 512 MB version (late 2012) and installed the Developer Preview of Java SE 8 for ARM on it. When I create a new Clojure project with Leiningen and launch the nREPL by doing lein repl it takes a bit more than two minutes (roughly 130 - 140 seconds) until the REPL has been initialized and can be used.

When launching the JAR file directly java -jar clojure-1.4.0/clojure-1.4.0 the REPL starts up in 25s.

I'm using fast class 10 SD cards (SanDisk Extreme with up to 30 MB/s). How come that the difference between using Leiningen with nRepl vs launching the JAR file is so big? What could be done to improve the startup time with Leiningen for the Raspberry Pi?


Source: (StackOverflow)

Where to find valid version numbers for dependencies in Leiningen

I'm new to Clojure and Leiningen, and I've determined that some of what I'll want to use is located in clojure.contrib.generic.math-functions. I found API information for that at http://richhickey.github.com/clojure-contrib/branch-1.1.x/math-api.html, but I can't find anything that helps me figure out what I should put into my project.clj file for that dependency.

I have tried [clojure.contrib.generic.math-functions "1.1"], [clojure.contrib.generic.math-functions "1.1.x"], and [clojure.contrib.generic.math-functions "1.1.0"]. For each of those, I get something like...

...
Caused by: org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
----------
1) clojure.contrib.generic.math-functions:clojure.contrib.generic.math-functions:jar:1.1

Source: (StackOverflow)

How to use library in maven repo for clojure project?

I use Leiningen to manage my CLJ project. When I want to wrap a Java library, I found that I have to introduce it to my project firstly.

How can I use a library in a Maven repo in my project?


Source: (StackOverflow)

How to install a leiningen plugin?

How do I install a leiningen plugin?

For example, leiningen-run?

I see this thing called "clojars.org", and how to "push" to it, but I don't see anything about "pulling" from it.


Source: (StackOverflow)