EzDevInfo.com

leiningen

Automate Clojure projects without setting your hair on fire.

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)

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)

Advertisements

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)

"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)

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)

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)

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)

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)

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)

leiningen - how to add dependencies for local jars?

I want to use leiningen to build and develop my clojure project. Is there a way to modify project.clj to tell it to pick some jars from local directories?

I have some proprietary jars that cannot be uploaded to public repos.

Also, can leiningen be used to maintain a "lib" directory for clojure projects? If a bunch of my clojure projects share the same jars, I don't want to maintain a separate copy for each of them.

Thanks


Source: (StackOverflow)

How to reload a clojure file in REPL

What is the preferred way of reloading functions defined in a Clojure file without having to restart the REPL. Right now, in order to use the updated file I have to:

  • edit src/foo/bar.clj
  • close the REPL
  • open the REPL
  • (load-file "src/foo/bar.clj")
  • (use 'foo.bar)

In addition, (use 'foo.bar :reload-all) does not result in required effect, which is evaluating the modified bodies of functions and returning new values, instead of behaving as the source haven't changed at all.


Source: (StackOverflow)

How to run .clj file as a script using leningen?

This is the second question after Is there a standalone Clojure package within Leiningen?

For example, I have a file hello_world.clj, and I can run it using

java -cp clojure.jar clojure.main hello_world.clj.

Since lein already contains Clojure (because I can run lein repl directly), is there a way to do the same thing like

lein script hello_world.clj by lein?


Source: (StackOverflow)

How do I find which of my dependencies is downloading a particular jar?

One of my project.clj's :dependencies is dependent on the monolithic clojure-contrib-1.1.0.jar, but I can't guess which one is downloading it. Short of incrementally commenting out each one, how can I discover which of them is responsible ?


Source: (StackOverflow)

How to Reload files upon save when using swank+leiningen+emacs

I'm looking to set up slime+lein-swank to reload source files referenced from the repl when i save the file. currently i do this:

  • edit file
  • save file
  • switch to repl
  • (use :reload-all 'com.package.namespace)
  • test stuff

I want to not have to remember to do step 4.


Source: (StackOverflow)

clojure and leiningen - using a git repository as dependency

Is it possible to have leiningen pull a project directly from a git repository (on github) as a dependency?

Using Bundler with Ruby, it is possible to map a gem to a git repo, allowing for rapid development and integration of dependent projects.

Update

Based on the accepted answer, there is now a leiningen plugin for managing git-deps: https://github.com/tobyhede/lein-git-deps


Source: (StackOverflow)