August 9, 2019

Community projects for Clojure CLI tools

clojure-cli logo - post topic

There are a number of tools from the Clojure community which add build tool features to the Clojure CLI tools. This enables developers to have a very lightweight and customisable set of tools that just do what they need.

This article just covers the very basics of each tool, see each projects documentation to get the full benefit of each tool.

  • depot finds newer versions of libraries (from Clojars and Git repositories)
  • kaocha full featured next gen Clojure test runner
  • depstar to package up your application for the JVM platform

Please see earlier articles in this series for background:

depot - find new library versions

depot will look for newer versions of the maven (clojars, maven central) and git dependencies in the project deps.edn file.

Install depot by adding an alias to the project deps.edn file or $HOME/.clojure/deps.edn file

:outdated {:extra-deps
            {olical/depot {:mvn/version "1.8.4"}}
           :main-opts ["-m" "depot.outdated.main"]}

To automatically update the dependency, add the --update option

:depot {:extra-deps
            {olical/depot {:mvn/version "1.8.4"}}
:outdated {:main-opts ["-m" "depot.outdated.main"]}
:outdated-update {:main-opts ["-m" "depot.outdated.main" "--version"]}}

Show the outdated dependencies with clojure -A:depot:outdated.

Automatically update the dependencies with clojure -A:depot:outdated-update

koacha test runner

koacha is a new test runner that works with Clojure CLI tools, Leiningen and Boot. Kaocha understands different types of tests including clojure.test, ClojureScript, Cucumber, Fudje, Expectations, allowing all tests to be handled in the same way. This test runner also produces very useful reports using pretty printing so its easy to get meaning from them.

Install by editing your deps.edn file and add an alias for kaocha

:test {:extra-deps
        {lambdaisland/kaocha {:mvn/version "0.0-529"}}}

Create a wrapper script called bin/kaocha

#!/usr/bin/env bash
clojure -A:test -m kaocha.runner "$@"

Create a tests.edn file at the root of the project. Start with a default configuration by just adding the following line:

#kaocha/v1 {}

Read the detailed documentation to get the most out of Kaocha.

depstar

depstar creates a jar of your application or uberjar that also includes the Clojure library and can be deployed directly on the JVM platform. depstar does not ahead of time (aot) compile your project.

Add the :depstar alias to the project deps.edn or $HOME/.clojure/deps.edn to make depstar available for all projects.

:aliases {:depstar
            {:extra-deps
               {seancorfield/depstar {:mvn/version "0.3.1"}}}}

Create a jar or uberjar file using the respective command:

clojure -A:depstar -m hf.depstar.jar myJar.jar
clojure -A:depstar -m hf.depstar.uberjar myUberJar.jar

The -v or --verbose after the filename lists all the files that are added to the jar file.

Add web assets into an uberjar by including an alias in your deps.edn:

{:paths ["src"]
 :aliases {:webassets {:extra-paths ["public-html"]}}}

Then invoke depstar with the chosen aliases:

clojure -A:depstar:webassets -m hf.depstar.uberjar MyProject.jar

An uberjar is run using the command:

java -jar MyProject.jar -m project.core

Other tools to investigate at another time

  • clj-kondo linter written in Clojure with GraphViz based dependency graph and other tools
  • juxt.pack to package your applications as a jar, uberjar, clojars, maven, lambda and docker
  • lein-tools-deps - dependencies with Leiningen
  • aka is for sharing aliases (not very clear what that means or why its useful - see project)
  • Plum is a tool for managing Clojure projects - a wrapper for several community projects.
  • version-clj Clojure & ClojureScript library for analysis and comparison of artifact version numbers (used by depot)
  • Meyvn enables you to generate uberjars (executables) and jars (libraries), and to deploy them on remote servers, e.g. Clojars
  • jet - CLI to transform between JSON, EDN and Transit, powered with a minimal query language.

Visit Sean Corfield's dot-clojure repository for more tools and how to configure them with Clojure CLI tools.

Interesting articles on Clojure CLI tools

Thank you.

@jr0cket

Tags: clojure-cli