Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Omit sources partially in Leiningen

I've got an API that I need to export, but a lot of code that I would like to keep from prying eyes. If I include :omit-sources true, then all of the codebase disappears, and my API is no longer available to compile against.

How could this be achieved? I will try to use git submodules, but I wonder if there is an alternative approach compatible with my current project layout, as in, exclude everything but a package.

Edit: I've got a data_readers.clj that won't make it into the JAR if I use :omit-sources

What I currently do is include :filespecs [{:type :bytes :path "data_readers.clj" :bytes ~(slurp "src/main/shared/clj/data_readers.clj")}]

to include the file manually, but this causes trouble in the Cursive IntelliJ plugin.

like image 460
user2424835 Avatar asked Jul 20 '15 13:07

user2424835


1 Answers

You need both :aot (ahead-of-time compilation) and :omit-source.

When :aot is not used (that's the default), clojure will try to compile the classes on the fly from the sources in the jar, so it needs the sources.

You can use :aot :all, or :aot [my.awesome.api] if you are going to expose just your api ns.

So your project.clj will look like:

(defproject my-project ... ... :aot :all :omit-source true)

This thread from the clojure mailing list has info about this. Also the compilation page in clojure.org explains the ahead-of-time compilation very well:

Clojure compiles all code you load on-the-fly into JVM bytecode, but sometimes it is advantageous to compile ahead-of-time (AOT). Some reasons to use AOT compilation are:

  • To deliver your application without source
  • To speed up application startup
  • To generate named classes for use by Java
  • To create an application that does not need runtime bytecode generation and custom classloaders
like image 67
nberger Avatar answered Sep 28 '22 12:09

nberger