Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude jars from a leiningen project?

While using Leiningen, I got the following abrupt error:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.tools.ant.util.FileUtils.getFileUtils()Lorg/apache/tools/ant/util/FileUtils; (core.clj:1)

I found the following answer at https://github.com/technomancy/leiningen/issues/194:

if ant version 1.6.1 is included in a project, lein fails. Autodoc "0.7.1" includes ant version 1.6.1.

a work around is to exclude ant.1.6.1 in the project.clj.    <--- *1*
But a better solution is changing the order of lein classpath.

from bin/lein   <--- *2*
CLASSPATH="$CLASSPATH:$LEIN_LIBS:$LEIN_DIR/src:$LEIN_DIR/classes:$LEIN_DIR/resources:$LEIN_JAR"
**changes to : **
CLASSPATH="$LEIN_LIBS:$LEIN_DIR/src:$LEIN_DIR/classes:$LEIN_DIR/resources:$LEIN_JAR;$CLASSPATH"

I read the Leiningen tutorial at https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md and the sample project.clj file at https://github.com/technomancy/leiningen/blob/stable/sample.project.clj, but I still have the following questions:

1) At the line marked 1, above, I can't tell how to exclude a specific version of a jar file.

2) At 2, above, exactly what is bin/lein? My Leiningen project doesn't have a bin directory, and Leiningen itself is a script, so there's no bin directory there?

Many thanks for your help.


Addendum 8/6/11: For the specific problem with Autodoc, I found a fork of Autodoc that fixes the problem for me. Just add "[org.clojars.weavejester/autodoc "0.9.0"]" to project.clj > defproject > :dev-dependencies clause. Then, from the command line (with the directory equal to the root of your leiningen project), execute 'lein autodoc', and wait for a while.

like image 543
Gregg Williams Avatar asked Jul 23 '11 17:07

Gregg Williams


1 Answers

In answer to (1) I'm not sure if he's saying that you need to exclude a specific version of Ant, but more likely that you can fix the issue by excluding the version of Ant that's pulled in by Autodoc (no matter what version). You could try something like:

(defproject my-project "1.0.0"
  :dependencies [[org.clojure/clojure "1.2.0"]
                 [org.clojure/clojure-contrib "1.2.0"]]
  :dev-dependencies [[autodoc "0.7.1" :exclusions [org.apache.ant/ant]]])

I've only excluded it in dev-dependencies here, assuming that Autodoc is only to be used during a build.

For (2), you are correct, Leiningen is a script, but in the issue report, the author is suggesting an edit to the Leiningen script to fix the issue by changing the order of directories referenced in Leiningen's CLASSPATH.

like image 74
Scott Avatar answered Sep 25 '22 20:09

Scott