Partially lower sources in Leiningen

I have an API that I need to export, but a lot of code that I would like to leave out of prying eyes. If I include: omit-sources true, then the entire code base disappears and my API is no longer compiled.

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

Edit: I have data_readers.clj that won't get into the JAR if I use: omit-sources

What I am doing now includes: filespecs [{: type: bytes: path "data_readers.clj": bytes ~ (slurp "src / main / shared / clj / data_readers.clj")}]

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

+5
source share
1 answer

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

When :aot not used (by default), clojure will try to compile classes on the fly from sources in the bank, so it needs sources.

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

So your project.clj will look like this:

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

This thread from the clojure mailing list contains information about this. In addition, the clojure.org page explains compilation very well in the future:

Clojure compiles all the code that you load on the fly into the JVM bytecode, but sometimes it is advantageous to collect leading (AOT). Some Reasons to use AOT compilation:

  • To deliver your application without source
  • To speed up the launch of the application
  • To create named classes for using Java
  • To create an application that does not require runtime bytecode generation and custom class loaders
+4
source

All Articles