• Stars
    star
    294
  • Rank 136,295 (Top 3 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created almost 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A new, simpler alternative to clj-new

deps-new Open in Gitpod Slack

A new, simpler alternative to clj-new.

Intended to be installed as a "tool" (Clojure CLI 1.10.3.933 or later).

clojure -Ttools install io.github.seancorfield/deps-new '{:git/tag "v0.5.2"}' :as new

Note: if you are on Windows, read Quoting keys and values in the official Deps and CLI Reference documentation to understand how the above command needs to look on Powershell. Or take a look at the Babashka CLI library support.

deps-new only supports :local/root and git-based coordinates, not Maven/Clojars coordinates. If you want an alternative that supports distributing your templates using Maven/Clojars look at clj-new but bear in mind I am no longer actively maintaining that.

Note: if you see instructions to use a template that look like clojure -A:new some-template :name whatever or clojure -Tnew some-template :name whatever, where some-template is not one of the built-in templates (app, lib, pom, scratch, template), those probably refer to clj-new rather than deps-new. Any templates other than the built-in ones are created and maintained by the community in repositories elsewhere, so please open issues or ask questions of the appropriate maintainer (not me).

The documentation here is structured as follows:

  • Motivation -- why does deps-new exist?
  • Create an Application -- how to create a basic application project, that can build an uberjar
  • Create a Library -- how to create a basic library project, that can build a JAR and deploy to Clojars
  • Create a Template -- how to create your own deps-new template project
  • Additional projects/files that deps-new can create (scratch, pom.xml)
  • More General Usage -- this includes links to additional documentation:
    • Project Names and Variables to see how the project name (:name) is used to derive the default values of all the built-in substitution variables
    • All the Options for the full list of command-line options available when invoking deps-new
    • Writing Templates for documentation on how to write your own templates

Followed by sections listing some community deps-new templates, integration with Emacs, some notes about the generated LICENSE file, and finally how to use deps-new with the Babashka CLI library.

Motivation

clj-new inherently carries along all of the baggage of lein new and boot new, including a modified chunk of Leiningen itself, as well as depending on Pomegranate for loading dependencies (so as to be compatible with Leiningen and Boot), and Stencil for the variable substitution in templates. The recently-released tools.build library, from the core Clojure team, provides all of the functionality needed to create new projects from templates, so deps-new aims to provide a wrapper around tools.build, some standard templates "out of the box", and machinery to allow you to easily write your own templates, mostly with no code needed at all.

The app and lib templates in deps-new are currently almost identical to those in clj-new, in terms of what they provide in generated projects, although they need no code: deps-new templates are primarily declarative, using a template.edn file to describe how parts of the template are copied into the target project folder.

You can get help on the available functions like this:

clojure -A:deps -Tnew help/doc

Create an Application

clojure -Tnew app :name myusername/mynewapp

Creates a directory mynewapp containing a new application project, with myusername as the "top" namespace and mynewapp as the main project namespace:

;; mynewapp/src/myusername/mynewapp.clj
(ns myusername.mynewapp
  (:gen-class))

(defn greet
  "Callable entry point to the application."
  [data]
  (println (str "Hello, " (or (:name data) "World") "!")))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (greet {:name (first args)}))

Create a Library

clojure -Tnew lib :name myusername/mycoollib

Creates a directory mycoollib containing a new library project, with myusername as the "top" namespace and mycoollib as the main project namespace under that.

If you want to generate the project into a different directory than the project name, use the :target-dir option to specify a path to the directory that should be created:

clojure -Tnew lib :name myusername/mycoollib :target-dir projects/newlib

Creates a directory projects/newlib containing a new library project, with myusername as the "top" namespace and mycoollib as the main project namespace under that.

Create a Template

clojure -Tnew template :name myusername/mytemplate

Creates a directory mytemplate containing a new template project, with myusername as the "top" namespace and mytemplate as the main project namespace under that. The generated template project will work as a template that produces a library project, but you can change it to produce whatever you want.

If you want to generate the project into a different directory than the project name, use the :target-dir option to specify a path to the directory that should be created:

clojure -Tnew template :name myusername/mytemplate :target-dir projects/newtemplate

Creates a directory projects/newtemplate containing a new library project, with myusername as the "top" namespace and mytemplate as the main project namespace under that.

Create a Minimal "scratch" Project

If you just want a very minimal deps.edn project to experiment with:

clojure -Tnew scratch :name play

Creates a directory play containing an empty deps.edn file and src/scratch.clj with a simple exec function (you can invoke via clojure -X scratch/exec) and a simple -main function (you can invoke via clojure -M -m scratch). This is intended to be a minimal "playground" to get started with deps.edn and the CLI.

If you want the scratch.clj file to have a different name, you can override the default with :scratch:

clojure -Tnew scratch :name play :scratch ground

The created file will be src/ground.clj in the play folder. :scratch can be a path:

clojure -Tnew scratch :name play :scratch play/ground

The created file will be src/play/ground.clj in the play folder.

Create a Fully-Fleshed pom.xml

clojure -Tnew pom :name com.acme/cool-lib :target-dir .

Creates a pom.xml file in the current directory (overwriting any existing file!) that has all the fields needed to publish a project to Clojars and have cljdoc.org generate the documentation, e.g.,

  <groupId>com.acme</groupId>
  <artifactId>cool-lib</artifactId>
  <version>0.1.0-SNAPSHOT</version>
  <name>com.acme/cool-lib</name>
  <description>FIXME: my new org.corfield.new/pom project.</description>
  <url>https://github.com/com.acme/cool-lib</url>
...
  <scm>
    <url>https://github.com/acme/cool-lib</url>
    <connection>scm:git:git://github.com/acme/cool-lib.git</connection>
    <developerConnection>scm:git:ssh://[email protected]/acme/cool-lib.git</developerConnection>
    <tag>v0.1.0-SNAPSHOT</tag>
  </scm>

You should run clojure -X:deps mvn-pom to synchronize the <dependencies> from your deps.edn file.

More General Usage

Currently those are the only five built-in templates (app, lib, pom, scratch, and template).

More general usage:

clojure -A:somealias -Tnew create :template com.acme.project/cool-lib :name myusername/mynewproject

Looks for com/acme/project/cool_lib/template.edn on the classpath (based on the :somealias alias) and, if present, uses that template to create a project, in mynewproject. Instead of -A:somealias, you could use -Sdeps to specify the dependencies needed to make the template available:

clojure -Sdeps '{:deps {com.acme.project/cool-lib COORDINATES}}' -Tnew create :template com.acme.project/cool-lib :name myusername/mynewproject

The COORDINATES could be something like {:local/root "/path/to/cool-lib"} for a template that exists on the local filesystem, or it could be based on :git/url/:git/sha etc for a template that exists in a git repository.

Note: because deps-new is based on tools.build and uses its file copying functions, the template must ultimately live on the filesystem, so :local/root and git-based coordinates are supported, but Maven/Clojars coordinates are not.

See Project Names and Variables to see how the project name (:name) is used to derive the default values of all the built-in substitution variables. See All the Options for the full list of command-line options available when invoking deps-new. See Writing Templates for documentation on how to write your own templates.

Practical.li also has an excellent guide to writing deps-new templates.

Templates

The following templates are available externally. If you have written a template and would like to add it to the list, please make a PR.

Emacs Integration

An emacs package is available which provides a Magit-style interface to clj-new and deps-new. It includes some community templates and welcomes for recommendations for more.

The Generated LICENSE File

The generated projects (from the built-in app, lib, and template templates) all contain a LICENSE file which is the Eclipse Public License (version 1.0) and that is also mentioned in the generated README.md files. This is a tradition that started with Leiningen's lein new and carried over into boot new and now clj-new. The idea is that it's better to ensure any open source projects created have a valid license of some sort, as a starting point, and historically most Clojure projects use the EPLv1.0 because Clojure itself and the Contrib libraries have all used this license for a long time.

You are not required to open source your generated project! Just because the projects are generated with an open source LICENSE file and have a License section in their README.md files does not mean you need to keep that license in place, if you do not want your project to be open source.

You are not required to use EPLv1.0 for your project! If you prefer a different license, use it! Replace the LICENSE file and update the README.md file to reflect your personal preference in licensing (I have tended to use the Apache License 2.0 in most of my open source projects, prior to working with Clojure, but see Prefer the MIT License for an alternative viewpoint from the folks who wrote XTDB).

Note: if you incorporate any source code from other people's open source projects, be aware of the legal implications and that you must respect whatever license they have used for that code (which may require you to release your enhancements under the same license and will, most likely, require you to include their copyright notices, etc). Do not copy other people's code without attribution!

Babashka CLI

The babashka CLI library allows you to call an -X (exec) function in a more Unixy way, without writing EDN on the command line. If you are dealing with quoting issues in your shell, this could be a viable alternative:

:new {:deps {org.babashka/cli {:mvn/version "0.2.15"}
             io.github.seancorfield/deps-new {:git/tag "v0.5.2"
                                              :git/sha "253f32a"}}
      :ns-default org.corfield.new
      :exec-args {} ;; insert default arguments here
      :main-opts ["-m" "babashka.cli.exec"]}

This allows you to call deps-new on the command line as:

$ clj -M:new app --name foo/bar --overwrite delete

License

Copyright Β© 2021-2023 Sean Corfield

Distributed under the Eclipse Public License version 1.0.

More Repositories

1

honeysql

Turn Clojure data structures into SQL
Clojure
1,706
star
2

next-jdbc

A modern low-level Clojure wrapper for JDBC-based access to databases.
Clojure
731
star
3

dot-clojure

My .clojure/deps.edn file
Clojure
613
star
4

usermanager-example

A little demo web app in Clojure, using Component, Ring, Compojure, Selmer (and a database)
Clojure
310
star
5

build-clj

Common build tasks abstracted into a library.
Clojure
154
star
6

readme

A testing library that turns your README into executable Clojure tests!
Clojure
143
star
7

vscode-calva-setup

My VS Code / Calva / Portal / Joyride setup
Clojure
83
star
8

om-sente

Playground to create Om + Sente test app
JavaScript
46
star
9

jsql

Basic DSL for generating SQL/DDL, formerly java.jdbc.sql and java.jdbc.ddl
Clojure
43
star
10

boot-tools-deps

A Boot task (deps) that wraps tools.deps(.alpha) to read deps.edn files
Clojure
39
star
11

engine

A Clojure library to implement a query -> logic -> updates workflow, to separate persistence updates from business logic, to improve testing etc.
Clojure
22
star
12

clj-soap

Fork of https://bitbucket.org/taka2ru/clj-soap updated to latest Clojure version
Clojure
21
star
13

lein-fregec

A Leiningen plugin to compile Frege (http://www.frege-lang.org) code.
Clojure
20
star
14

atom-chlorine-setup

My Atom / Chlorine setup
Clojure
17
star
15

socket-rebl

A Socket REPL that also submits forms to Cognitect's REBL
Clojure
13
star
16

next.jdbc.xt

Experimental extension of next.jdbc to work with XTDB 2.0 (snapshots)
Clojure
12
star
17

ring-cfml

A version of Ring (Clojure) for CFML
ColdFusion
12
star
18

polylith-external-test-runner

An external (subprocess) test runner for Polylith
Clojure
10
star
19

java-clojure-example

Trivial example to show using Java from Clojure in deps.edn project
Clojure
8
star
20

datamapper

A couple of CFCs from the World Singles data mapper to show how we wrap Clojure (vectors of) hashmaps to present a thin OO veneer to our CFML code.
ColdFusion
8
star
21

liquid-setup

Configuration for the Liquid in-process Clojure editor
Clojure
7
star
22

boot-kotlinc

A Kotlin compilation task for Boot
Clojure
6
star
23

macro-day

Code examples I wrote during Amit Rathore's "A day with Clojure macros" training
Clojure
6
star
24

edmund

Edmund is an Event-Driven Model micro-framework for CFML / ColdFusion
ColdFusion
5
star
25

build-uber-log4j2-handler

A conflict handler for log4j2 plugins cache files for the tools.build uber task.
Clojure
4
star
26

avowal

Futures and Promises for modern CFML, inspired by my earlier cfconcurrency library
ColdFusion
3
star
27

datafy-nav-example

Examples of datafy and nav
Clojure
3
star
28

lein-fw1

A Leiningen plugin to create and manage FW/1 projects.
Clojure
3
star
29

cfml-interop

CFML/Clojure interop library extracted from World Singles code and open sourced!
Clojure
3
star
30

clojure-dining-car

A Categorized and Annotated Directory of Clojure Libraries
2
star
31

orm-blog

A very simple blog/cms built in ColdFusion using Framework 1 and ORM.
ColdFusion
2
star
32

intro2fp

Code samples for Introduction to Functional Programming talk, cf.Objective() 2011
ColdFusion
2
star
33

cat-genetics

Utilities to help calculate TICA-specific color cat genetics etc
Clojure
2
star
34

clojure-lucee

A toy example of running CFML pages via Lucee as an embedded engine in a Clojure Ring application.
Clojure
2
star
35

lightstuff

Historical archive of Peter Bell's LightBase and LightGen utility framework/code
ColdFusion
2
star
36

poly-classloader-bug

Repro for a potential classloader bug for poly test
Clojure
1
star
37

dojo-anthem

Team 1's code from the January 2013 San Francisco Clojure Dojo - to play the National Anthem
Clojure
1
star
38

cursive-expectations

Example of using Expectations with Cursive
Clojure
1
star
39

spd1

Introduction to Systematic Program Design Part 1 - some Clojure examples
Clojure
1
star
40

ordered-subset

Clojure
1
star
41

HUnitFrege

A port of HUnit from Haskell to Frege (WIP -- not even compiling yet!)
Frege
1
star
42

cfo2013

Code examples for my cf.Objective() 2013 presentations
ColdFusion
1
star
43

clojure-test

A place to discuss clojure.test concerns and possible enhancements
1
star
44

boot-localrepo

Boot tasks that wrap lein-localrepo functionality
Clojure
1
star
45

seancorfield.github.io

An Architect's View - my blog and personal web site
HTML
1
star
46

polylith-issue146

Repro for the setup-fn problem with the issue-146 branch
Clojure
1
star
47

WeeklyWrongChallenge

The weekly challenge repo for WPW
Clojure
1
star
48

ring-async-bug

SSCCE of Ring with async on Jetty that fails with thread death
Clojure
1
star
49

avaus-tv

Simulation of Avaus-TV prize draw, in Clojure
Clojure
1
star
50

hello-compojure

The Compojure template, but without lein-ring
Clojure
1
star
51

cfbloggers

Clojure scratch code to parse and analyze the feeds at coldfusionbloggers.org
Clojure
1
star