本文介绍了为什么leiningen做一个目录层次结构?我可以不用它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用leiningen创建一个新的clojure项目,它会创建一个目录树,如下:

 
| - doc
| ` - intro.md
| - project.clj
| - README.md
| - src
| ` - hello_friend
| ` - core.clj
` - test
` - hello_friend
` - core_test.clj

通常,我想要的是一个单独的clojure文件,我想使用leiningen来处理库并启动一个repl。



我有两个问题:



(1)可以使用此结构

 
| - project.clj
` - hello.clj

我非常喜欢。 (实际上更好的是将project.clj作为hello.clj文件的一部分)



(2)深层目录结构有什么好的理由?






注意,只要我能看到: / p>

project.clj

 通用0.0.0
:dependencies
[[org.clojure / clojure1.4.0]
[hiccup1.0.2]]
:source-paths [。]
:main two

:repl-options {:port 4001:init(println(-main)to run)}

one.clj

 (ns one 
(:use hiccup.core))

(def doom(html [:h1doom]))

two.clj

 (ns two 
(:require one))

(defn -main []
(println one / doom))

(1)您可以指定 source-paths [。] 。有关所有可能的选项,请参阅lein



(2)在你有2个命名空间和一个 require s之后,你需要deep结构。有关命名空间如何映射到文件的说明,请参见。


If I create a new clojure project with leiningen, it makes a directory tree like so:

.
|-- doc
|   `-- intro.md
|-- project.clj
|-- README.md
|-- src
|   `-- hello_friend
|       `-- core.clj
`-- test
    `-- hello_friend
        `-- core_test.clj

Often, all I want is a single clojure file, and I want to use leiningen to handle libraries and start a repl.

I've got two questions:

(1) Is is possible to get leiningen to work properly with this structure

.
|-- project.clj
`-- hello.clj

which I'd greatly prefer. (In fact even better would be to have the project.clj as part of the hello.clj file)

(2) Is there any good reason for the deep directory structure? Or is it just a habit from java-land?


Note, this works fine as far as I can see:

project.clj

(defproject generic "0.0.0"
  :dependencies
  [[org.clojure/clojure "1.4.0"]
   [hiccup "1.0.2"]]
  :source-paths ["."]
  :main two

  :repl-options { :port 4001 :init (println "(-main) to run") }
)

one.clj

(ns one
  (:use hiccup.core))

(def doom (html [:h1 "doom"]))

two.clj

(ns two
  (:require one))

(defn -main []
  (println one/doom))
解决方案

(1) You can specify :source-paths ["."] in your project.clj. See lein sample project for all possible options

(2) You need the "deep" structure once you have 2 namespaces and one requires on the other. See here for an explanation of how namespaces are mapped to files.

这篇关于为什么leiningen做一个目录层次结构?我可以不用它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 00:10