Scala
Overview
Clever Cloud deploys Scala and Java applications built with sbt. This page explains how to set up your application. To deploy a Play Framework application, see the dedicated pages for Play Framework 1.x and Play Framework 2.x.
Configure your Scala application
Mandatory configuration
Your application listens on 0.0.0.0, on the port of the http.port system property. Clever Cloud sets it to 8080, or 9000 with Request Flow: Play applications read it, so you have nothing to do. Learn more about the port of your application.
sbt Native Packager
We rely on sbt-native-packager to run applications. This tool automates project build and provides a stage task which is run during deployment. To use it, add this line to project/plugins.sbt (with an up-to-date version):
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.11.4")Then you need to enable the package in build.sbt:
enablePlugins(JavaAppPackaging)
// Disable javadoc packaging to speed up the build
Compile / packageDoc / mappings := Seq()For more information, please have a look at the sbt-native-packager documentation
sbt custom goal
By default, the deployment system executes sbt stage and runs a binary from target/universal/stage/bin. When this folder holds several scripts, the choice isn’t guaranteed: set CC_SBT_TARGET_BIN to the one you want to run. To build with another goal, set the CC_SBT_BUILD_GOAL environment variable, for example CC_SBT_BUILD_GOAL="clean stage".
To pass arguments to the binary when it starts, set CC_SBT_DEPLOY_ARGS, for example CC_SBT_DEPLOY_ARGS="-Dconfig.resource=clevercloud.conf". The former SBT_DEPLOY_GOAL name remains supported as an alias of CC_SBT_DEPLOY_ARGS, but it no longer adds goals to the build command: if you used it to build a specific module, move that goal to CC_SBT_BUILD_GOAL.
Multi-module build
If you have a single repository with multiple modules or if you want to build a specific module in a monorepo (with no top-level stage task), you must set CC_SBT_BUILD_GOAL, CC_SBT_TARGET_DIR, and CC_SBT_TARGET_BIN. For instance, if you want to deploy a module named service1 that produces a binary named my-binary, configuration should be:
CC_SBT_BUILD_GOAL=service1/stage
CC_SBT_TARGET_DIR=service1
CC_SBT_TARGET_BIN=my-binaryThe build command is sbt service1/stage and the application is started with service1/target/universal/stage/bin/my-binary.
When you set CC_RUN_COMMAND, Clever Cloud runs it as is and ignores CC_SBT_TARGET_DIR and CC_SBT_TARGET_BIN to start your application.
HOCON users
If you’re using HOCON configuration files, then you can have direct acces to environment variables from the configuration file:
application.secret=${APPLICATION_SECRET}Monitor your application with New Relic
You can use New Relic to monitor your application on Clever Cloud.
Please refer to our New Relic documentation to configure it for your application.
Environment injection
Clever Cloud injects the environment variables of your application into its environment, along with those of its linked add-ons.
Custom build configurations
On Clever Cloud you can define some build configuration: like the app folder to deploy or the path to validate your application deployment is ready To do that follow the documentation here and add the environment variable you need.
In Scala code, retrieve an environment variable with System.getenv("MY_VARIABLE"), it returns null when the variable is not defined.