Migrating Projects To Clojure Cli Tools

Migrating to Clojure CLI tools only requires the addition of a deps.edn configuration to the project. A user level configuration containing a collection of community tools) minimizes the project configuration required.

Magic Leiningen plugins

A few Leiningen plugins inject code into a project to make it work. For example, lein-ring injects clojure code into the project to run an application server. These type of plugins may require updates to the Clojure code in the project.

Minimal approach

Create a deps.edn file in the root of the project directory, containing an empty hash-map, {}

The Clojure version will be taken from the Clojure CLI tools install configuration.

This configuration is enough to run a terminal REPL UI for the project, although requiring some namespaces from a project may require libraries to be added as dependencies first.

Adding dependencies

All Clojure projects require the org.clojure/clojure library and a specific version is defined in the configuration that comes with the Clojure CLI install.

Use the :deps key in deps.edn to specify a version of the org.clojure/clojure library, along with any dependencies required for the Clojure code to run.

{:deps
 {org.clojure/clojure {:mvn/version "1.10.2"}
  integrant/integrant {:mvn/version "0.8.0"}}}

Hot loading dependencies

add-lib can hot-load a Clojure dependency into a running REPL process, avoiding the need to restart.

Adding paths

It is advisable to specify the directory paths to define the location of the source code in the project, especially when running the project in other environments such as a continuous integration server.

Edit the deps.edn file in the root of the project directory and add source directory and if relevant the resources directory.

{:paths
   ["src" `resource`]}

Adding a test runner

Tests can be run locally using a test runner alias from the user wide configuration.

A Continuous Integration server requires an alias in the project deps.edn file to define a test runner. A selection of test runners are provided by practicalli/clojure-deps-edn. Copy a test runner alias to the project deps.edn file.

Building a jar or uberjar from the project

The depstar project is provided in practicalli/clojure-deps-edn for building jars for libraries and uberjars for applications. When pushing a project to a Continuous Server, the relevant alias should be included in the Clojure projects deps.edn file so the project can be built

Deployment

A Continuous Delivery pipeline will require an alias in the project deps.edn file to define how to build a jar or uberjar to package the Clojure project.

Tools for migration

Several tools exist to support migration

  • lein-to-deps - create a deps.edn configuration from a project.clj configuration
  • lein-tools-deps - share Clojure CLI dependencies with Leiningen project configuration.

results matching ""

    No results matching ""