exclude certain clj namespaces from compilation in leiningen

3.3k views Asked by At

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]}})
3

There are 3 answers

10
runexec On

Try this (ns ^:skip-aot my-ns)

You can also do

(ns ^{:skip-aot true} my-ns
    (require [...]))

Source

1
amalloy On

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"]
0
djhaskin987 On

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.