Heroku Scala Support
Last updated 22 July 2015
The Heroku Cedar stack is capable of running a variety of types of Scala applications.
This document describes the general behavior of the Cedar stack as it relates to the recognition and execution of Scala applications. For a more detailed explanation of how to deploy an application, see:
Scala applications are recognized when files matching any of the following patterns are found:
When a deployed application is recognized as a Scala application, Heroku responds with
-----> Scala app detected.
$ git push heroku master -----> Scala app detected
If an application also contains a
/conf/application.conf file, a Play 2.0 application is detected and Heroku responds with
-----> Play 2.0 app detected. Please see the Heroku Play Support article for more information.
Scala applications that use Maven can be deployed as well, but they will be treated as Java applications, so Heroku Java Support will apply.
The following environment variables will be set:
PORT: HTTP port to which the web process should bind
DATABASE_URL: URL of the Heroku Postgres database connection
When a Java process is started on your dyno, the follow Java options will automatically be picked up:
These options are configured as part of the environment variable
JAVA_TOOL_OPTIONS, which is intended to augment a command line in environments where the command-line cannot be accessed or modified. If you need to override these settings you can either define your preferred options in the
Procfile command (which will take precedence), or set your own
JAVA_TOOL_OPTIONS config var.
Adjusting Environment for a Dyno Size
When a new dyno size is selected, the following settings are automatically added to
- free, hobby or standard-1x:
Monitoring Resource Usage
Additional JVM flags can be used to monitor resource usage in a dyno. The following flags are recommended for monitoring resource usage:
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+UseConcMarkSweepGC
See the troubleshooting article for more information about tuning a JVM process.
Applications must include a
/project/build.properties file with the
sbt.version property specifying a version of SBT between 0.11.0 and 0.13.8. SBT release candidates, betas and other pre-release versions are allowed.
The Heroku Scala buildpack will run
sbt compile stage to build the application. Applications must include a
stage task, which performs any tasks needed to prepare an application to be run in-place. For example, Typesafe’s
sbt-native-packager adds a
stage task to SBT that generates start scripts for an application. To use the plugin, create a
/project/plugins.sbt file containing:
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.8.0")
In some cases, builds need to clean artifacts before compiling. If a clean build is necessary, configure builds to perform
clean by setting
$ heroku config:set SBT_CLEAN=true Setting config vars and restarting example-app... done, v17 SBT_CLEAN: true
All subsequent deploys will use the
clean task. To remove the
clean task, unset
$ heroku config:unset SBT_CLEAN Unsetting SBT_CLEAN and restarting example-app... done, v18
By default, Scala applications are launched with a start script generated by the
If an application is not using the
sbt-native-packager or should be launched in a different way, a custom
Procfile can be included in the root of the project specifying a different entry for the
The Play framework automatically generates a start script for you, so no additional plugins are needed.
Supported Java versions
Heroku currently uses OpenJDK 8 to run your application. OpenJDK versions 6 and 7 are available.
You’re able to select Java 6, 7, or 8. Depending on which you select the latest available version of that Java runtime will be used each time you deploy your app.
Current versions are:
- Java 7 -
- Java 8 -
The JDK that your app uses will be included in the slug, which will affect your slug size.
Specifying a Java version
You can specify a Java version by adding a file called
system.properties to your application.
Set a property
java.runtime.version in the file:
1.8 is the default so if you’d like to use Java 8 you don’t need this file at all. You can specify JDK 7 by setting this property to “1.7”.
A Heroku Postgres starter-tier database add-on is automatically provisioned for Scala applications. This populates the
DATABASE_URL environment variable.