Fork me on GitHub
#deps-new
<
2021-09-16
>
Carsten Behring13:09:54

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.

Carsten Behring13:09:28

Asking it for the option is confusing:

clj  -A:project/new -h

Carsten Behring13:09:57

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

Carsten Behring13:09:03

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 ?

seancorfield17:09:29

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

Carsten Behring13:09:22

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

Carsten Behring14:09:09

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

Carsten Behring14:09:23

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

Carsten Behring14:09:06

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

Carsten Behring14:09:55

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

Carsten Behring14:09:27

anu idea what could be wrong ?

Carsten Behring14:09:00

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

Carsten Behring14:09:02

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

Carsten Behring14:09:25

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

seancorfield16:09:27

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

seancorfield17:09:29

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

dorab23:09:52

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.

seancorfield23:09:42

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

seancorfield23:09:11

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

dorab23:09:49

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

seancorfield23:09:23

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

dorab23:09:40

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

seancorfield23:09:35

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

seancorfield23:09:59

Having test and ci is "minimally functioning".

dorab23:09:07

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.

seancorfield23:09:10

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

seancorfield23:09:56

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.

seancorfield23:09:51

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

dorab23:09:20

Okay. That works for me.