I have a question. Why compile fails when the copy part is skipped?
(b/copy-dir {:src-dirs ["src/clj" "src/cljc" "env/prod/clj"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs ["src/clj" "src/cljc" "env/prod/clj"]
:class-dir class-dir})
This doesn't compile. deps.edn
{:paths
["src"]
:aliases
{:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
:ns-default build}}}
build.clj
(ns build
(:require [clojure.string :as string]
[clojure.tools.build.api :as b]))
(def basis (b/create-basis {:project "deps.edn"}))
(defn alt [_]
(b/compile-clj {:basis basis
:src-dirs ["env"]
:class-dir "target"}))
env/core.clj
(ns core)
(defn testfn []
(println "hello"))Using :build :paths doesn't help either
{:paths
["src"]
:aliases
{:build {:paths ["env"]
:deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
:ns-default build}}}{:paths
["env"]
:aliases
{:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
:ns-default build}}}
or
{:paths
["env"]
:aliases
{:build {:paths ["env"]
:deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
:ns-default build}}}
works.So :build :paths is ignored. Only top level :paths is used. Is there a problem with tools.build or tools.dep.alpha?
your :build alias describes the execution environment for the build program. :paths there is not ignored, but it's affecting the classpath of the build program.
when you are compiling, that is a separate program, forked by the build program and using (by default) the basis of your main deps.edn (not the :build alias), but really the basis it uses is up to you
this line:
(def basis (b/create-basis {:project "deps.edn"}))
is the one defining what is on the classpath during compilation (because you are passing that basis to compile-cljthere's so many things above I'm not sure what problem you're actually trying to solve at this point, but that's the important thing to know in getting it to do what you want. If you have optional things to put in the classpath of your compile, you can do that by supplying :aliases on the basis call (see the https://clojure.github.io/tools.build/clojure.tools.build.api.html#var-create-basis api for details)
Given the build.clj and env/core.clj above, how should I set deps.edn so that it compiles?
I checked /tmp/com*/compile.args the classpath matches what I set in :paths but not :build :paths
(ns build
(:require [clojure.string :as string]
[clojure.tools.build.api :as b]))
(defn alt [_]
(b/compile-clj {:src-dirs ["env"]
:class-dir "target"}))
also failstools.build guide says top level :paths is replaced with "." plus extra :paths under :build alias.
I am not able to validate that in my testing.
ok never mind i think i get you now
In kit-clj setup, there's the shared source code in src/, and dev code in env/dev/ and prod code in env/prod. What's the best way to configure deps.edn and/or :build alias to include only src/ and env/prod for compilation?
I guess that's why kit-clj opt to copy source code into target for prod build
You can create a separate alias pulling in env/prod and then use that when you make the basis to do compilation
Great. This is it. Tyvm! deps.edn
:aliases {:prod {:extra-paths ["env/prod/clj"]}}
build.clj
(def basis (b/create-basis {:project "deps.edn", :aliases [:prod]}))is there kit/net/env.clj in the class-dir ?
I guess that shouldn't matter given the :src-dirs in compile-clj
re "Clojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779" - that directory is a temp dir that contains the results of the failed compile
you can inspect the compile.args and compile.clj files in that directory
it's basically running (in that directory) java with the args in compile.args, which should execute the compile.clj file (which shows what's being compiled)
compile.args reveals the problem:
"env/prod/clj" has to go into deps.edn top level :paths not the build alias level :paths
fail how? (stacktrace)
{:clojure.main/message
"Execution error (ExceptionInfo) at clojure.tools.build.tasks.compile-clj/compile-clj (compile_clj.clj:112).\nClojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779\n",
:clojure.main/triage
{:clojure.error/class clojure.lang.ExceptionInfo,
:clojure.error/line 112,
:clojure.error/cause
"Clojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779",
:clojure.error/symbol
clojure.tools.build.tasks.compile-clj/compile-clj,
:clojure.error/source "compile_clj.clj",
:clojure.error/phase :execution},
:clojure.main/trace
{:via
[{:type clojure.lang.ExceptionInfo,
:message
"Clojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779",
:data {},
:at
[clojure.tools.build.tasks.compile_clj$compile_clj
invokeStatic
"compile_clj.clj"
112]}],
:trace
[[clojure.tools.build.tasks.compile_clj$compile_clj
invokeStatic
"compile_clj.clj"
112]
[clojure.tools.build.tasks.compile_clj$compile_clj
invoke
"compile_clj.clj"
80]
[clojure.lang.Var invoke "Var.java" 384]
[clojure.tools.build.api$compile_clj invokeStatic "api.clj" 312]
[clojure.tools.build.api$compile_clj invoke "api.clj" 272]
[build$main invokeStatic "build.clj" 73]
[build$main invoke "build.clj" 68]
[clojure.lang.AFn applyToHelper "AFn.java" 154]
[clojure.lang.AFn applyTo "AFn.java" 144]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.core$apply invokeStatic "core.clj" 667]
[clojure.core$apply invoke "core.clj" 662]
[clojure.run.exec$exec invokeStatic "exec.clj" 48]
[clojure.run.exec$exec doInvoke "exec.clj" 39]
[clojure.lang.RestFn invoke "RestFn.java" 423]
[clojure.run.exec$_main$fn__205 invoke "exec.clj" 180]
[clojure.run.exec$_main invokeStatic "exec.clj" 176]
[clojure.run.exec$_main doInvoke "exec.clj" 139]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.core$apply invokeStatic "core.clj" 667]
[clojure.main$main_opt invokeStatic "main.clj" 514]
[clojure.main$main_opt invoke "main.clj" 510]
[clojure.main$main invokeStatic "main.clj" 664]
[clojure.main$main doInvoke "main.clj" 616]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.main main "main.java" 40]],
:cause
"Clojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779",
:data {}}}Cleaning target
Preparing main jar...
Execution error (FileNotFoundException) at kit.net.web.middleware.core/loading (core.clj:1).
Could not locate kit/net/env__init.class, kit/net/env.clj or kit/net/env.cljc on classpath.$ find env/prod/
env/prod/
env/prod/resources
env/prod/resources/logback.xml
env/prod/clj
env/prod/clj/kit
env/prod/clj/kit/net
env/prod/clj/kit/net/env.cljThreads, please. Don't post walls of text into the channels.