This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-16
Channels
- # announcements (19)
- # babashka (13)
- # beginners (7)
- # calva (8)
- # cider (25)
- # clj-kondo (12)
- # cljsrn (7)
- # clojure (60)
- # clojure-australia (5)
- # clojure-europe (59)
- # clojure-france (14)
- # clojure-gamedev (2)
- # clojure-nl (1)
- # clojure-uk (7)
- # clojurescript (43)
- # community-development (8)
- # core-async (2)
- # cursive (15)
- # datomic (75)
- # deps-new (31)
- # depstar (1)
- # fulcro (6)
- # graalvm (53)
- # holy-lambda (1)
- # juxt (3)
- # jvm (13)
- # kaocha (8)
- # lsp (109)
- # malli (14)
- # off-topic (62)
- # pathom (11)
- # pedestal (12)
- # polylith (12)
- # releases (5)
- # sci (5)
- # shadow-cljs (15)
- # sql (16)
- # tools-deps (27)
- # vim (1)
- # xtdb (14)
I am using the praticelli aliases which has this for deps-new: :project/new {:replace-deps {com.github.seancorfield/clj-new {:mvn/version "1.1.331"}} :exec-fn clj-new/create :exec-args {:template lib :name practicalli/playground} :main-opts ["-m" "clj-new.create"]} I have a hard time using it.... The options for creating from a custom template are not clear to me, after reading documentation.
Asking it for the option is confusing:
clj -A:project/new -h
it tells me this in first line: WARNING: Use of -A with clojure.main is deprecated, use -M instead Usage: clojure -X:project/add clj-new/create :template template-name :name project-name options
First I get a warning, and the it tells me for usage "clojure -X:project/add clj-new/create", which I did not type. Is this a side effect of the alias ?
The -M
/ :main-opts
style invocation is "legacy" and is no longer documented. The -X
invocation style has been preferred for some time. The -T
"tools" invocation is the best approach if you're using a recent version of the Clojure CLI (1.10.3.933 or later).
But even typing the right thing, does give a very confusing error:
clojure -X:project/add clj-new/create :template clj-py-r-template/clj-template :name me/my-app
Failed with: Failed to resolve version for clj-py-r-template:lein-template.clj-template:jar:RELEASE: Could not find metadata clj-py-r-template:lein-template.clj-template/maven-metadata.xml in local (/home/carsten/.m2/repository)
Execution error (ExceptionInfo) at clj-new.helpers/resolve-remote-template (helpers.clj:171).
Could not load artifact for template: clj-py-r-template/clj-template
Tried coordinates:
[clj-py-r-template/boot-template.clj-template "RELEASE"]
[clj-py-r-template/lein-template.clj-template "RELEASE"]
For more detail, enable verbose logging with :verbose 1, 2, or 3
I am digging...
My maven folder of the template contains basically empty folders only, no jar or whatever.
.:
total 20
drwxr-xr-x 5 carsten carsten 4096 Sep 16 15:59 .
drwxr-xr-x 166 carsten carsten 4096 Sep 16 15:59 ..
drwxr-xr-x 2 carsten carsten 4096 Sep 16 16:00 boot-template.clj-template
drwxr-xr-x 2 carsten carsten 4096 Sep 16 16:00 clj-template.clj-template
drwxr-xr-x 2 carsten carsten 4096 Sep 16 16:00 lein-template.clj-template
./boot-template.clj-template:
total 12
drwxr-xr-x 2 carsten carsten 4096 Sep 16 16:00 .
drwxr-xr-x 5 carsten carsten 4096 Sep 16 15:59 ..
-rw-r--r-- 1 carsten carsten 315 Sep 16 16:00 resolver-status.properties
./clj-template.clj-template:
total 12
drwxr-xr-x 2 carsten carsten 4096 Sep 16 16:00 .
drwxr-xr-x 5 carsten carsten 4096 Sep 16 15:59 ..
-rw-r--r-- 1 carsten carsten 315 Sep 16 16:00 resolver-status.properties
./lein-template.clj-template:
total 12
drwxr-xr-x 2 carsten carsten 4096 Sep 16 16:00 .
drwxr-xr-x 5 carsten carsten 4096 Sep 16 15:59 ..
-rw-r--r-- 1 carsten carsten 315 Sep 16 16:00 resolver-status.properties
So it could not find the thing in clojars, I suppose. But it is there: https://clojars.org/clj-py-r-template/clj-template
anu idea what could be wrong ?
it worked for sure some time ago, with older versions of clj-new, maybe a year ago
I figured it ou after a while: This works:
clojure -X:project/new clj-new/create :template clj-py-r-template :name me/my-app
so without the "/clj-template" suffix in the template name
@seancorfield I did a PR to clarify the documentation: https://github.com/seancorfield/clj-new/pull/77
@carsten.behring Note that is clj-new
not deps-new
-- the former can process Leiningen and Boot template whereas the latter does not: it is deps.edn
specific and uses a declarative form of template. I accepted your PR (thank you!) and have done some additional editing to clarify how qualified template names work (including linking to Leiningen's page about templates).
The -M
/ :main-opts
style invocation is "legacy" and is no longer documented. The -X
invocation style has been preferred for some time. The -T
"tools" invocation is the best approach if you're using a recent version of the Clojure CLI (1.10.3.933 or later).
Thanks for this
Would it make sense to add (def clean bb/clean)
to the build.clj
created by deps-new
? Similarly have a jar
and uber
function that just turns around and calls the bb
version? That way there'd be a minimally useful build.clj
.
@dorab In addition to the test
and ci
tasks they already have you mean?
(ns build
(:refer-clojure :exclude [test])
(:require [org.corfield.build :as bb]))
(def lib 'app/app)
(def version "0.1.0-SNAPSHOT")
(def main ')
(defn test "Run the tests." [opts]
(bb/run-tests opts))
(defn ci "Run the CI pipeline of tests (and build the uberjar)." [opts]
(-> opts
(assoc :lib lib :version version :main main)
(bb/run-tests)
(bb/clean)
(bb/uber)))
The idea is to encourage folks to always run tests before building the JAR -- and this way if the tests fail, your JAR doesn't get built (and target
doesn't get deleted from any prior run).
I'd rather not encourage building a JAR without running the tests...
I was surprised when I tried to run clj -T:build clean
in a directory that was newly created by deps-new
. I would expect that deps-new
created a minimally functioning build.clj
- meaning that it could run the following tasks clean
, jar
, test
, and uber
(for apps).
If a project is newly created, you wouldn't need to run clean
. The ci
task calls clean
prior to calling jar
or uber
.
Having test
and ci
is "minimally functioning".
Okay. I get what you're saying. The model I had in my head was that the build.clj
created by deps-new
would have all the basic functionality (like a Makefile). If I wanted something different, I was of course able to modify it as I wished - but that there would be an example of how the "standard" tasks were defined. Perhaps a different approach might be to have the basic clean
and jar
tasks in the
, but commented out. So, that someone could uncomment them as needed.
Look at https://github.com/seancorfield/next-jdbc/blob/develop/build.clj and https://github.com/seancorfield/honeysql/blob/develop/build.clj and https://github.com/clojure-expectations/clojure-test/blob/develop/build.clj -- real-world projects that have just "run tests", ci
, and deploy
(which a fresh lib project from deps-new
has -- the app project doesn't have/need deploy
).
If someone wants to add direct clean
and/or jar
tasks to
(ns build
(:refer-clojure :exclude [test])
(:require [clojure.tools.build.api :as b] ; for b/git-count-revs
[org.corfield.build :as bb]))
(def lib 'lib/lib)
(def version "0.1.0-SNAPSHOT")
#_ ; alternatively, use MAJOR.MINOR.COMMITS:
(def version (format "1.0.%s" (b/git-count-revs nil)))
(defn test "Run the tests." [opts]
(bb/run-tests opts))
(defn ci "Run the CI pipeline of tests (and build the JAR)." [opts]
(-> opts
(assoc :lib lib :version version)
(bb/run-tests)
(bb/clean)
(bb/jar)))
(defn deploy "Deploy the JAR to Clojars." [opts]
(-> opts
(assoc :lib lib :version version)
(bb/deploy)))
they can just add the functions and copy parts of ci
into them.But I would discourage that approach and so I don't want them in the build.clj
file out of the box.