英文:
File core.clj is not under a source root error in intellij
问题
我在Clojure项目中使用IntelliJ IDEA,刚刚开始时遇到了"File core.clj is not under a source root"的消息,该项目有两个文件夹:.idea和src,在src文件夹中,我有一个core.clj文件,其中显示了项目的结构。这是包含项目结构的照片。
我没有源根目录,我只创建了core.clj、deps.edn文件和Deps_project.iml文件,没有其他文件,我该如何解决这个问题?我需要再写一个文件吗?
英文:
I am using IntelliJ IDEA in a Clojure project, I just started but I get the message "File core.clj is not under a source root", the project has 2 folders: .idea and src, inside src I got the core.clj file in which showing the structure of the project. This is the photo containing the structure of the project.
I have no source root, I just created the core.clj and the deps.edn file and the Deps_project.iml file, nothing else, how can I solve this? Do I need to write another file?
答案1
得分: 0
只需要两个文件用于您的项目:
在文件 deps.edn 中:
{:paths ["src"]
:deps {org.clojure/spec.alpha {:mvn/version "0.3.218"}}}
在文件 src/spec_tutorial/core.clj 中:
(ns spec-tutorial.core
(:require [clojure.spec.alpha :as s]))
请注意,Clojure 命名空间与源文件路径之间存在对应关系,但要注意,命名空间中的连字符 - 在路径名称中会被翻译为下划线 _。
英文:
You need just two files for your project:
In file deps.edn
{:paths ["src"]
:deps {org.clojure/spec.alpha {:mvn/version "0.3.218"}}}
In file src/spec_tutorial/core.clj
(ns spec-tutorial.core
(:require [clojure.spec.alpha :as s]))
Note there is a correspondence between the Clojure namespace and the source file path, but beware that hyphens - in namespaces are translated to underscores _ in path names.
答案2
得分: 0
你的目录结构应该如下所示:
./deps.edn
./src/spec_tutorial/core.clj
其中 ./ 前缀是 Unix 风格的项目目录缩写。
因此,./src 部分是由 deps.edn 中的 :paths 行确定的。spec_tutorial/core.clj 部分来自命名空间 spec-tutorial/core,而 .clj 后缀是文件类型。
另外,请注意,在命名空间中的连字符会在文件/目录名称中变成下划线。
另一个观察:请不要在文件 core.clj 中包含 :test-paths,就像你的截图中所示。
英文:
Your directory tree should look like so:
./deps.edn
./src/spec_tutorial/core.clj
where the ./ prefix is unix-style shorthand for the project directory.
So, the ./src part is determined by the :paths line in deps.edn. The spec_tutorial/core.clj part is from the namespace spec-tutorial/core, and the .clj suffix is the "file-type".
Also, note that hyphens in the namespace become underscores in the file/directory names.
Another observation: Do not include :test-paths in the file core.clj as seen in your screenshot.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论