简体   繁体   English

文件 core.clj 不在 intellij 中的源根错误下

[英]File core.clj is not under a source root error in intellij

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.我在 Clojure 项目中使用 IntelliJ IDEA,我刚开始但收到消息“文件 core.clj 不在源根目录下”,该项目有 2 个文件夹: .ideasrc ,在src中我得到了core.clj显示项目结构的文件。 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?我没有源根,我只是创建了core.cljdeps.edn文件以及Deps_project.iml文件,没有别的,我该如何解决这个问题? Do I need to write another file?我需要写另一个文件吗?

You need just two files for your project:您的项目只需要两个文件:

In file deps.edn在文件deps.edn

{:paths ["src"]
 :deps  {org.clojure/spec.alpha {:mvn/version "0.3.218"}}}

In file src/spec_tutorial/core.clj在文件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.请注意,Clojure 命名空间与源文件路径之间存在对应关系,但请注意,命名空间中的连字符-会转换为路径名中的下划线_

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.其中./前缀是项目目录的 unix 风格简写。

So, the ./src part is determined by the :paths line in deps.edn .因此,./src 部分由./src中的:pathsdeps.edn The spec_tutorial/core.clj part is from the namespace spec-tutorial/core , and the .clj suffix is the "file-type". spec_tutorial/core.clj部分来自命名空间spec-tutorial/core.clj后缀是“文件类型”。

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.另一个观察结果:不要在文件core.clj中包含:test-paths ,如屏幕截图所示。

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

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