Docs menu

Scala on Primcloud

How Primcloud detects a Scala app, builds it with sbt, and starts the packaged app.

On this page

Detection#

Primcloud builds your app as Scala when the root of your repo has any of:

  • A file with the .sbt extension, usually build.sbt
  • project/build.properties
  • A .scala file under project/
  • A .scala file under .sbt/

sbt and the JDK#

sbt. The build uses exactly the sbt version in project/build.properties:

project/build.properties
sbt.version=1.11.7

It's required; without sbt.version, the build fails with "No sbt version defined". sbt 1.x and 2.x are supported, except 2.0.0, which has a plugin-loading bug; use 2.0.1 or later.

JDK. The build installs OpenJDK, the latest LTS unless system.properties names a version:

system.properties
java.runtime.version=25

See Runtime versions for both.

The build#

The build runs:

Terminal
sbt compile stage

compile builds your Scala sources. stage is expected to produce a runnable output. Most apps get stage for free from sbt-native-packager. Play enables it automatically through PlayScala, and any other project can enable it explicitly:

project/plugins.sbt
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.11.7")
build.sbt
enablePlugins(JavaAppPackaging)

sbt-native-packager writes a runnable app to target/universal/stage/bin/<app-name>, which your Procfile invokes at launch.

To add tasks, replace them, or clean first, see Customizing the build.

Your dependencies, sbt, and the JDK are reused from the previous build, so later builds don't download everything again. They're only there during the build; to keep sbt available to your running app, which is rarely needed, set sbt.available-at-launch=true in system.properties or an SBT_AVAILABLE_AT_LAUNCH=true secret.

How the app launches#

A Procfile is required, running what stage produced. For a typical sbt-native-packager build:

Procfile
web: target/universal/stage/bin/my-app -Dhttp.port=${PORT}

Replace my-app with the name from your build.sbt. See Formations.

Port. Your web process must listen on $PORT; other process types don't get one. Play and most sbt-native-packager output take -Dhttp.port=$PORT as shown; Akka HTTP, http4s, and plain servlet apps need the equivalent flag for their own server.

Environment. Every process gets these, plus your secrets:

Variable Value Purpose
JAVA_HOME Path to the installed OpenJDK So the JVM launcher finds its runtime.
PATH With $JAVA_HOME/bin prepended So java is on PATH.
JAVA_TOOL_OPTIONS Memory settings for your formation's size JVM options applied without editing your command.
PORT Assigned by Primcloud Set on the web process only.

Database URL. If you set a DATABASE_URL in the URI shape postgres://user:pass@host:port/db, Primcloud also sets JDBC_DATABASE_URL, JDBC_DATABASE_USERNAME, and JDBC_DATABASE_PASSWORD variables from it, handy when your Scala code, or a pool like HikariCP, wants a jdbc:postgresql://... URL directly. Remove DATABASE_URL if you don't want them.