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
  • Deploying Scala and Play Applications with the Heroku sbt Plugin

Deploying Scala and Play Applications with the Heroku sbt Plugin

English — 日本語に切り替える

Last updated April 29, 2020

Table of Contents

  • Adding the plugin
  • Deploying with the plugin
  • Advanced configuration
  • Deploying to multiple applications
  • Requirements

In addition to Git deployment, Heroku supports building and releasing apps via an API. The Heroku sbt 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 that 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 sbt Plugin in your project, configure it, and deploy your application to Heroku.

Adding the plugin

To include the plugin in your project, add the following to your project/plugins.sbt file:

addSbtPlugin("com.heroku" % "sbt-heroku" % "2.1.4")

If you’re not using Play, then you’ll also need to add the sbt-native-packager plugin. You can do this by adding the following to your project/plugins.sbt:

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.5.2")

Then run sbt update to ensure the new dependencies are downloaded.

Next, we must configure the name of the Heroku application the plugin will deploy to. But first, create a new app. Install the Heroku CLI and run the create command with the -n flag, which will prevent it from adding a Git remote.

$ heroku create -n
Creating obscure-sierra-7788... done, stack is heroku-18
http://obscure-sierra-7788.herokuapp.com/ | git@heroku.com:obscure-sierra-7788.git

Now add something like this to your build.sbt, but replace “obscure-sierra-7788” with the name of the application you created.

herokuAppName in Compile := "obscure-sierra-7788"

You’re ready to deploy.

Deploying with the plugin

To create the slug and deploy it to Heroku, run the following command:

$ sbt stage deployHeroku
...
[info] -----> Packaging application...
[info]        - app: obscure-sierra-7788
[info]        - including: target/universal/stage/
[info] -----> Creating build...
[info]        - file: target/heroku/build.tgz
[info]        - size: 47MB
[info] -----> Uploading slug... (100%)
[info]        - success
[info] -----> Deploying...
[info] remote:
[info] remote: -----> sbt-heroku app detected
[info] remote: -----> Installing JDK 11... done
[info] remote: -----> Discovering process types
[info] remote:        Procfile declares types -> console, web
[info] remote:
[info] remote: -----> Compressing...
[info] remote:        Done: 106.5M
[info] remote: -----> Launching...
[info] remote:        Released v3
[info] remote:        https://obscure-sierra-7788.herokuapp.com/ deployed to Heroku
[info] remote:
[info] -----> Done
[success] Total time: 113 s (01:53), completed Jan 17, 2020 11:39:21 AM

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.

Advanced configuration

The sbt plugin allows for several advanced configuration settings. All of these settings are defined in the build.sbt file. For example, you may set the desired JDK version like so:

herokuJdkVersion in Compile := "11"

For a list of supported JDK versions, see Heroku Java Support.

You can set configuration variables as a Map:

herokuConfigVars in Compile := Map(
  "MY_VAR" -> "some value",
  "JAVA_OPTS" -> "-Xmx384m -Xss512k -XX:+UseCompressedOops"
)

Be aware that any variable defined in herokuConfigVars will override defaults, or previously defined config vars.

You may set process types (similar to a Procfile) with herokuProcessTypes:

herokuProcessTypes in Compile := Map(
  "web" -> "target/universal/stage/bin/my-app -Dhttp.port=$PORT",
  "worker" -> "java -jar target/universal/stage/lib/my-worker.jar"
)

And finally, you can include additional directories in the slug like this (note that they must be relative to the project root):

herokuIncludePaths in Compile := Seq(
  "app", "conf/routes", "public/javascripts"
)

By default, the plugin will package the essential directories under your project’s target directory, so including additional directories should not be necessary in most cases.

Deploying to multiple applications

Most real applications will be required to deploy to multiple Heroku apps (such as dev, test, and prod). Normally this is done with multiple Git remotes. But with the plugin you can use either system properties, environment variables, or any other native sbt/Java configuration method. For example, you might define your herokuAppName with a Map and choose a value with a system property like this:

herokuAppName in Compile := Map(
  "test"  -> "your-heroku-app-test",
  "stage" -> "your-heroku-app-stage",
  "prod"  -> "your-heroku-app-prod"
).getOrElse(sys.props("appEnv"), "your-heroku-app-dev")

Then run an sbt command similar to this:

$ sbt -DappEnv=test stage deployHeroku

Requirements

The plugin has a few restrictions that must be considered.

  • It is required that your project use sbt 0.13.5 or greater.

  • You must use Java 1.7 or higher locally.

  • The plugin does not support Play 2.0 or 2.1.

For more information on the plugin and Scala in general, see Heroku’s Scala support. For more information on sbt, see the sbt documentation.

Keep reading

  • Scala

Feedback

Log in to submit feedback.

Using Node.js to Perform JavaScript Optimization for Play and Scala Applications Deploying Scala Apps on Heroku

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