deps-new

2021-09-16T13:53:54.022800Z

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.

2021-09-16T13:54:28.023300Z

Asking it for the option is confusing:

clj  -A:project/new -h

2021-09-16T13:54:57.023800Z

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

2021-09-16T13:56:03.025100Z

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 ?

seancorfield 2021-09-16T17:06:29.033400Z

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).

2021-09-16T13:57:22.025700Z

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

2021-09-16T14:00:09.026100Z

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

2021-09-16T14:01:50.026400Z

I am digging...

2021-09-16T14:02:23.027100Z

My maven folder of the template contains basically empty folders only, no jar or whatever.

2021-09-16T14:03:06.027400Z

.:
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

2021-09-16T14:04:55.028100Z

So it could not find the thing in clojars, I suppose. But it is there: https://clojars.org/clj-py-r-template/clj-template

2021-09-16T14:05:27.028500Z

anu idea what could be wrong ?

2021-09-16T14:06:00.029200Z

it worked for sure some time ago, with older versions of clj-new, maybe a year ago

2021-09-16T14:09:02.029600Z

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

2021-09-16T14:18:25.030100Z

so without the "/clj-template" suffix in the template name

2021-09-16T14:18:59.030800Z

@seancorfield I did a PR to clarify the documentation: https://github.com/seancorfield/clj-new/pull/77

seancorfield 2021-09-16T16:57:27.033200Z

@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).

2021-09-16T19:30:45.034Z

Thanks for this

dorab 2021-09-16T23:18:52.037Z

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.

seancorfield 2021-09-16T23:29:42.037800Z

@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)))

seancorfield 2021-09-16T23:31:11.038900Z

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).

dorab 2021-09-16T23:31:49.039600Z

Yes, in addition to the ci and test that are already there.

seancorfield 2021-09-16T23:32:23.040Z

I'd rather not encourage building a JAR without running the tests...

dorab 2021-09-16T23:37:40.043600Z

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).

seancorfield 2021-09-16T23:41:35.044500Z

If a project is newly created, you wouldn't need to run clean. The ci task calls clean prior to calling jar or uber.

seancorfield 2021-09-16T23:41:59.045100Z

Having test and ci is "minimally functioning".

dorab 2021-09-16T23:48:07.050100Z

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.

seancorfield 2021-09-16T23:50:10.051300Z

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).

seancorfield 2021-09-16T23:51:56.052500Z

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.

seancorfield 2021-09-16T23:52:51.053200Z

But I would discourage that approach and so I don't want them in the build.clj file out of the box.

dorab 2021-09-16T23:54:20.053700Z

Okay. That works for me.