Deploying Clojure Applications with the Heroku Leiningen Plugin
Last updated September 17, 2020
Table of Contents
The Heroku Leiningen Plugin is deprecated and no longer under active development.
Existing setups using this plugin will continue to work for the foreseeable future. However, we advise customers to migrate to another deployment mechanism since this plugin will not be updated to include security fixes, support for more recent Java/Clojure versions or new features. Customers that require deployment of pre-built uberjars can use the Heroku Java CLI plugin.
For more information about the deployment of Clojure applications on Heroku, see Deploying Clojure Apps on Heroku.
In addition to Git deployment, Heroku supports building and releasing apps via an API. The lein-heroku plugin uses this API to provide direct deployment of prepackaged standalone web applications to Heroku.
This may be a preferred approach for applications that take a long time to compile or need to be deployed from a continuous integration server such as Travis CI or Jenkins.
In this article, you’ll learn how to include the Heroku Leiningen Plugin in your project, configure it, and deploy your application to Heroku.
Adding the plugin
To include the plugin in your project, add the latest version of the Leiningen plugin to your project.clj
file’s :plugins
vector, for example:
[lein-heroku "0.5.3"]
Install the Heroku CLI and run the create
command.
$ heroku create
Creating obscure-sierra-7788... done, stack is heroku-18
http://obscure-sierra-7788.herokuapp.com/ | git@heroku.com:obscure-sierra-7788.git
If you do not have a Heroku Git repo in your git remote
s, add something like this to your project.clj
.
:heroku {:app-name "your-heroku-app-name"}
Make sure your project has a Procfile, and you’re ready to deploy.
Deploying an app
Run the following command from the root directory of your project to deploy the app to Heroku:
$ lein heroku deploy
-----> Packaging application...
- app: obscure-sierra-7788
- including: target/clojure-getting-started-standalone.jar
-----> Creating build...
- file: target/heroku/slug.tgz
- size: 5MB
-----> Uploading build...
- success
-----> Deploying...
remote:
remote: -----> Fetching custom tar buildpack... done
remote: -----> JVM Common app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing... done, 53.9MB
remote: -----> Launching... done, v6
remote: https://obscure-sierra-7788.herokuapp.com/ deployed to Heroku
remote:
-----> Done
Visit your application with this command:
$ heroku open -a obscure-sierra-7788
Or view the logs with this command:
$ heroku logs -a obscure-sierra-7788
The Heroku CLI will allow you to access the application, and run commands just like an application deployed with git push
.
Configuring the plugin
You may set a :heroku
element in your project.clj
like this:
:heroku {
:app-name "your-heroku-app-name"
:jdk-version "1.8"
:include-files ["target/myapp.jar"]
:process-types { "web" "java -jar target/myapp.jar" }}
By default, the plugin will include the target
directory in your slug file.
Requirements
- Your application must be built as an uberjar.
- You must use Java 1.7 or higher locally.
For more information on the plugin and Clojure in general, see Heroku’s Clojure support. For more information on Leiningen, see the Leiningen documentation.