Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude certain clj namespaces from compilation in leiningen

I have a project that works fine using lein run. Now I want to compile it into a standalone jar using lein uberjar. However, there are a couple of source files in my src/projectname/ directory called e.g. playground.clj and stats.clj that I use for experimenting with emacs & the repl, but that I don't want to compile for the final project.

With something like make, I would specify all files that should be compiled. With clojure/leiningen, it seems, all files are compiled by default - how can I exclude files? I haven't found anything in the leiningen docs.

I am currently using :aot :all. Is this the place to change something? Again, I couldn't find detailed documentation on this.

UPDATE:

The suggestions so far haven't worked. What has worked, however, is to include all desired namespaces instead of excluding the ones that should not be compiled. E.g.:

(defproject myproject "version"
  ;; ...
  :profiles {:uberjar {:aot [myproject.data
                             myproject.db
                             myproject.util]}})
like image 898
pholz Avatar asked Dec 02 '14 10:12

pholz


2 Answers

Have a look at leiningen's sample project.clj, which describes how to use :jar-exclusions or :uberjar-exclusions to exclude arbitrary paths when creating jars (resp. uberjars).

  ;; Files with names matching any of these patterns will be excluded from jars.
  :jar-exclusions [#"(?:^|/).svn/"]
  ;; Files with names matching any of these patterns will included in the jar
  ;; even if they'd be skipped otherwise.
  :jar-inclusions [#"^\.ebextensions"]
  ;; Same as :jar-exclusions, but for uberjars.
  :uberjar-exclusions [#"META-INF/DUMMY.SF"]
like image 146
amalloy Avatar answered Nov 07 '22 12:11

amalloy


Old question, but I think I found the answer for those coming after me.

I found the answer in the link to the sample leiningen project from @amalloy's answer, except instead of :jar-exclusions I use source-paths, here.

The idea is to create two separate source directories, one for stuff you don't care to spread around and one for stuff you do:

dev-src/<your-project>/playground.clj
dev-src/<your-project>/stats.clj
src/<your-project>/<everything-else>

Then, in your project.clj, include src in source-paths normally, and include emacs-src in a special profile where your want it visible, say the usual :dev profile:

{
   ;; ...
   :source-paths ["src"]
   :profiles {
      :dev {
         :source-paths ["src" "dev-src"]
      }
   }
}

That way when you're messing around on your machine those files will be in the jar, and when you deploy to clojars or compile with uberjar they will not be included in the jar, nor compiled.

like image 1
djhaskin987 Avatar answered Nov 07 '22 12:11

djhaskin987