Heroku Scala Support

Last Updated: 19 June 2015

cedar scala

Table of Contents

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:

Getting Started with Scala on Heroku


Scala applications are recognized when files matching any of the following patterns are found:

  • /*.sbt
  • /project/*.scala
  • /project/build.properties
  • /.sbt/*.scala

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:

  • PATH: .sbt_home/bin:/usr/local/bin:/usr/bin:/bin
  • JAVA_OPTS: -Xss512k -XX:+UseCompressedOops
  • PORT: HTTP port to which the web process should bind
  • DATABASE_URL: URL of the Heroku Postgres database connection

Resizing dynos automatically changes Java memory settings. The JAVA_OPTS config var can be manually adjusted to override these defaults.

When a Java process is started on your dyno, the follow Java options will automatically be picked up:

  • -Dfile.encoding=UTF-8 -Djava.rmi.server.useCodebaseOnly=true

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 JAVA_TOOL_OPTIONS:

  • free, hobby or standard-1x: -Xmx384m -Xss512k
  • standard-2x: -Xms768m
  • performance: -Xmx4g

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.

Build behavior

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")

Clean builds

In some cases, builds need to clean artifacts before compiling. If a clean build is necessary, configure builds to perform clean by setting SBT_CLEAN=true:

$ heroku config:set SBT_CLEAN=true
Setting config vars and restarting example-app... done, v17

All subsequent deploys will use the clean task. To remove the clean task, unset SBT_CLEAN:

$ heroku config:unset SBT_CLEAN
Unsetting SBT_CLEAN and restarting example-app... done, v18

Runtime behavior

By default, Scala applications are launched with a start script generated by the sbt-native-packager:

web: target/universal/stage/bin/appname

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 web process.

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 6 - 1.6.0_27
  • Java 7 - 1.7.0_79
  • Java 8 - 1.8.0_40

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.