如何在 lein 项目中编译不在 "src" 下的 clojure 模块

How to compile clojure modules that are not under "src" in a lein project

我使用 lein new app hello 构建了我的项目,所以我有这个结构

.
└── src
    └── hello
        └── core.clj
└── project.clj
└── test
└── ..

我想在我的项目中添加另一个辅助模块,这样我就可以在测试和 src 模块中使用代码,因为我希望它与 src 目录分离。

所以我添加了一个助手模块

.
└── src
    └── hello
        └── core.clj
└── project.clj
└── test
└── helpers
    └──hello
         └── helpers.clj

如何更改我的 project.clj 文件以使 lein run 编译。 lein run 不编译并在我尝试要求 helpers 命名空间时抛出以下错误。

Exception in thread "main" java.lang.ClassNotFoundException: hello.helpers, compiling:(hello/core.clj:7:3)

我的 project.clj 文件看起来像默认文件:

(defproject hello "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]]
  :main ^:skip-aot hello.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

然而,在 IDE(IntelliJ) 中,它在 REPL 中运行良好,不会抛出 class 未找到异常。

添加

:source-paths ["src" "helpers"]

到您的 project.clj 文件。