Deploying a tools.deps Clojure project to Heroku 6 February, 2019

Recently the offical Clojure-buildpack on Heroku added support for Clojure's CLI tools.

This is some great news as it opens the door to hosting tools.deps Clojure projects on Heroku - no Leiningen required.

Though as the Clojure-buildpack still assumes a Leiningen-project, some small tweaks are needed when using tools.deps.

Let's dive in!

two-step

There are two things we need to take care of in order to deploy a tools.deps project:

ensure the project is seen as a Clojure-project override the build-step

quack like Leiningen

In order for our project to be build by the Clojure-buildpack, we need to make sure it 'looks like' a Leiningen-project.

We accomplish this by adding an empty file project.clj to the root of our project.

building

Nextup is the actual build-step. By default this will invoke Leiningen to build an uberjar. We can override this by adding an executable script bin/build with the tools.deps equivalent of lein uberjar .

There're several tools for creating uberjars with tools.deps. For this example we'll use depstar and add the following alias to deps.edn :

;; deps.edn { .. . :aliases { :depstar { :extra-deps {seancorfield/depstar { :mvn/version " 0.1.5 " }}}} }

Then in bin/build we provide the command to create our application's uberjar:

#!/usr/bin/env bash clojure -A:depstar -m hf.depstar.uberjar foo.jar

Note:

make sure to use clojure and not clj as the latter will trigger an error (ie Please install rlwrap for command editing or use "clojure" instead. )

and not as the latter will trigger an error (ie ) don't forget to chmod +x bin/build or else the file is ignored

or else the file is ignored if you need a specific version of the Clojure CLI tools, set the config variable CLOJURE_CLI_VERSION with one of the versions listed here.

As a final step, make sure the Procfile contains the command to start the application:

web: java -cp foo.jar clojure.main -m foo.core

That's it! You're one git push heroku master away from deploying your tools.deps project to Heroku.

resources