Fork me on GitHub
#leiningen
<
2022-08-02
>
bastilla16:08:31

Is it possible to have different :source-paths? And then to combine these :profiles? Means :source-paths from different profiles get merged? This does not seem to be the case - right? Apart from a certain setting that addresses "env/dev/src" and "env/prod/src" (and test) which works, this does not seem to be a working mechanism. This is a pity. My new project has a setting with PostgreSQL and another build targets H2. So I have two scaffolding code sections which cannot be splitted during runtime. Hence, I came up with this idea in my project.cls:

:source-paths ["src/clj" "src/cljs" "src/cljc"]

  :aliases {"remote"    ["with-profile" "dev/postgresql" "do"
                         ["clean"]
                         ["run" "-m" "storyarcher.core"]]
            "embedded"  ["with-profile" "dev/h2" "do"
                         ["clean"]
                         ["run" "-m" "storyarcher.core"]]}
  
  :profiles {:dev             [:project/dev :profiles/dev :db/postgresql]
             :dev/postgresql  [:project/dev :profiles/dev :db/postgresql]
             :dev/h2          [:project/dev :profiles/dev :db/h2]
             :test            [:project/dev :project/test :profiles/test]

             :project/dev  {:jvm-opts ["-Dconf=dev-config.edn"]
                            ...usual stuff...
                            :source-paths ["env/dev/clj" "env/dev/cljs" "test/cljs"]}

             :db/postgresql {:source-paths ["srcadds/clj/db/postgresql" "env/dev/clj" "env/dev/cljs" "test/cljs"]}
             :db/h2         {:source-paths ["srcadds/clj/db/h2"         "env/dev/clj" "env/dev/cljs" "test/cljs"]}
But I get
$ lein remote
Exception in thread "main" Syntax error macroexpanding clojure.core/ns at (storyarcher/db/adds.clj:1:1).
...Ton of thread stack... then:
Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/ns did not conform to spec. {:clojure.spec.alpha/problems 
... Tons of specs... not important, I think, then:
Error encountered performing task 'do' with profile(s): 'dev,dev,postgresql'
Suppressed exit
and my IDE (VS Code Calva) tells me, that these particular files in srcadds have this problem in line 1 (defining namespace), quote: > Can't parse /home/ak/data/private-projects/StoryArcher/tmp/thisisit/storyarcher/srcadds/clj/db/postgresql/storyarcher/db/adds.clj, Unparsable namespace formclj-kondo(syntax) So defining different :source-paths in different :profiles and then combining them and addressing them via :aliases call is not a feasable thing in Leiningen. Is that correct? Thanks for hints and your time!

bastilla16:08:40

I forgot, the file srcadds/clj/db/postgresql/storyarcher/db/adds.clj starts with (line 1):

(ns storyarcher.db.adds
  (:require [[cheshire.core :refer [generate-string parse-string]]
which looks pretty normal to me.

dpsutton16:08:22

that’s an invalid ns form

dpsutton16:08:55

>

Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/ns did not conform to spec.
(:require [[cheshire.core :refer [generate-string parse-string]] isn’t valid.

dpsutton16:08:09

(:require [cheshire.core :refer […]] …)

bastilla16:08:05

Hrmm... I see an "extra" [] around the stuff in :require. Could that be the culprit? Here is the total line:

(ns storyarcher.db.adds
  (:require [[cheshire.core :refer [generate-string parse-string]]
             [next.jdbc.date-time]
             [next.jdbc.prepare]
             [next.jdbc.result-set]])
  (:import (org.postgresql.util PGobject)))

dpsutton16:08:23

100% that’s the error

dpsutton16:08:29

it is an invalid ns form

bastilla16:08:41

Bingo! (Sometimes I long for Javas strong typing again.) 1000 thanks!

dpsutton16:08:21

you are getting a type error. It said “invalid ns form”. You just skipped over what the type error was telling you

bastilla16:08:41

True. Yet I was looking over that line one bazillion times, and the IDE failed to point me idiot to the right spot. But thanks, I really appreciate it!

dpsutton16:08:12

Do you have a linter installed? I get an error on the ns form

dpsutton16:08:59

and if i eval that in my repl it highlights the part it cannot parse:

Syntax error macroexpanding clojure.core/ns at (REPL:85:1).
((:require [[cheshire.core :as json] [clojure.test :refer :all] [metabase.api.geojson :as api.geojson] [metabase.http-client :as client] [metabase.models.setting :as setting] [metabase.test :as mt] [metabase.util :as u] [metabase.util.schema :as su] [schema.core :as s]])) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form

bastilla16:08:25

I do have linter, and Calva told me "Can't parse" though not as precise as your REPL approach. I was fixed on the first line, which was marked red, not the second line. I confess, often times I get lost in the woods of parentheses.

dpsutton16:08:29

fair enough.