Deploying Kotlin Apps on Heroku
Last updated 20 June 2017
This article describes how to take an existing Kotlin app and deploy it to Heroku.
If you are new to Heroku and Kotlin, you might want to start with the Getting Started with Kotlin on Heroku tutorial.
The tutorial assumes that you have:
- an existing Kotlin app that uses Maven or Gradle as a build tool
- a free Heroku account
- the Heroku CLI installed
- a Java JDK installed
Deploying a Kotlin app on Heroku is identical to any Maven or Gradle based application on Heroku. If you’re using Gradle, you’ll want to read our guide to Deploying Gradle Apps on Heroku first.
Before advancing through this guide, please ensure that you can build your application locally with either a
Procfile is a text file in the root directory of your application that defines process types and explicitly declares what command should be executed to start your app. Most applications will need a Procfile to run on Heroku. The
Procfile tells Heroku what command to use to run your application. In a few specific cases, Heroku can automatically determine the appropriate command to use (such as when using Spring Boot), but it’s often still preferable to customize this value.
The following example shows a typical
Procfile for a Spring Boot app built with Gradle:
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/demo-0.0.1-SNAPSHOT.jar
The example declare a single process type,
web, and the command needed to run it. The name “web” is important. It declares that this process type will be attached to the HTTP routing stack of Heroku, and receive web traffic when deployed.
You can configure many aspects of your Heroku application through environment variables. For example, you might define the
_JAVA_OPTIONS environment variable by running the following command from the CLI:
$ heroku config:set _JAVA_OPTIONS="-Dfile.encoding=UTF-8"
Other aspects of your Kotlin application can be configured with the
system.properties file. This file is used to set the JDK version Heroku will install with your app. The
system.properties file resides in the root directory of your repo (alongside the
Procfile), and may look like this:
For a complete list of supported versions, see the Heroku guide for Java.
Kotlin applications can be deployed at Heroku as precompiled JAR files and WAR files. This avoids the need for Git and does not require uploading your source code to Heroku. Depending on your application, you can choose from the following:
- Heroku Maven Plugin to deploy executable JAR files and WAR files from your Maven configuration.
- Heroku Gradle Plugin to deploy executable JAR files.
- Heroku CLI Deploy Plugin to deploy executable JAR files and WAR files independent of your build system.
For more information on the details of Heroku’s Java Support, include supported JDK versions, see the Heroku Java Support article.