Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Language Support
  • Scala
  • Heroku Scala Support

Heroku Scala Support

English — 日本語に切り替える

Last updated November 28, 2022

Table of Contents

  • Activation
  • Environment
  • Build behavior
  • Runtime behavior
  • Add-ons

This document describes the general behavior of Heroku 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

Activation

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.

Environment

The following environment variables will be set:

  • PATH: .sbt_home/bin:/usr/local/bin:/usr/bin:/bin
  • 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

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:

  • eco, basic or standard-1x: -Xmx350m -Xss512k
  • standard-2x: -Xmx768m
  • performance-m: -Xmx2g
  • performance-l: -Xmx12g

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 1.x. 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" % "1.7.6")

Or you can write a custom stage task by putting something like this in your build.sbt:

val stage = taskKey[Unit]("Stage task")

val Stage = config("stage")

stage := {
  (packageWar in Compile).value
  (update in Stage).value.allFiles.foreach { f =>
    if (f.getName.matches("webapp-runner-[0-9\\.]+.jar")) {
      println("copying " + f.getName)
      IO.copyFile(f, baseDirectory.value / "target" / "webapp-runner.jar")
    }
  }
}

You can test your task by running sbt compile stage locally.

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
SBT_CLEAN: true

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 JDK versions

Heroku currently uses OpenJDK 8 to run your application. OpenJDK version 7 is available. Depending on what major version you select the latest available update of that Java runtime will be used each time you deploy your app. For a list of current versions see the Java support article.

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:

java.runtime.version=1.8

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”. For details on how to set specific update versions, see the Java support article.

Add-ons

A Heroku Postgres starter-tier database add-on is automatically provisioned for Scala applications. This populates the DATABASE_URL environment variable.

Keep reading

  • Scala

Feedback

Log in to submit feedback.

Using Node.js to Perform JavaScript Optimization for Play and Scala Applications Reducing the Slug Size of Play 2.x Applications

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences