简体   繁体   English

从 leiningen 的编译中排除某些 clj 命名空间

[英]exclude certain clj namespaces from compilation in leiningen

I have a project that works fine using lein run .我有一个使用lein run可以正常工作的项目。 Now I want to compile it into a standalone jar using lein uberjar .现在我想使用lein uberjar将它编译成一个独立的 jar。 However, there are a couple of source files in my src/projectname/ directory called eg 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.但是,在我的src/projectname/目录中有几个源文件,例如playground.cljstats.clj ,我用它们来试验 emacs 和 repl,但我不想为最终项目编译。

With something like make , I would specify all files that should be compiled.使用make东西,我会指定所有应该编译的文件。 With clojure/leiningen, it seems, all files are compiled by default - how can I exclude files ?使用 clojure/leiningen,似乎所有文件都是默认编译的 -如何排除文件 I haven't found anything in the leiningen docs.我在 leiningen 文档中没有找到任何内容。

I am currently using :aot :all .我目前正在使用: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.然而,有效的是包含所有需要的命名空间,而不是排除那些不应编译的命名空间。 Eg:例如:

(defproject myproject "version"
  ;; ...
  :profiles {:uberjar {:aot [myproject.data
                             myproject.db
                             myproject.util]}})

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).看看leiningen 的示例 project.clj ,它描述了如何使用:jar-exclusions:uberjar-exclusions在创建 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"]

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 .我在@amalloy 的回答中的示例 leiningen 项目的链接中找到了答案,除了:jar-exclusions在这里使用source-paths

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:然后,在您的 project.clj 中,通常将src包含在source-paths ,并将emacs-src包含在您希望它可见的特殊配置文件中,例如通常的:dev配置文件:

{
   ;; ...
   :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.这样,当您在机器上乱搞时,这些文件将位于 jar 中,而当您部署到 clojars 或使用 uberjar 进行编译时,它们将不会包含在 jar 中,也不会被编译。

Try this (ns ^:skip-aot my-ns)试试这个(ns ^:skip-aot my-ns)

You can also do你也可以这样做

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

Source 来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM