Packaging Scala Handler Code with sbt¶
You can use the Scala build tool (sbt) to build and package your code as an assembly JAR. You can use the sbt-assembly plugin to create a JAR file containing all of the dependencies.
Once you have a JAR file, you can upload the file to a Snowflake stage, then reference it in the IMPORTS parameter in the CREATE FUNCTION or CREATE PROCEDURE statement that you use to create the function or procedure . For more information on uploading JAR files, refer to Making Dependencies Available to Your Code. For more information on choosing whether to have code inline or on a stage, refer to Keeping Handler Code In-line or on a Stage.
To create an assembly JAR file with your handler code, use the following steps.
In the directory containing your
build.sbtfile, in the
project/subdirectory, create a file named
For example, if the directory containing your
hello-snowpark/, create the file
hello-snowpark/ |-- build.sbt |-- project/ |-- plugins.sbt
plugins.sbtfile, add the following line:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
This adds the sbt-assembly plugin to your project.
If your project requires multiple versions of the same library (e.g. if your project depends on two libraries that require different versions of a third library), define a merge strategy in your
build.sbtfile to resolve the dependencies. See Merge Strategy for details.
If your project requires the Snowpark library, refer to it in your
libraryDependencies, as shown below. Be sure to use at least the minimum version required.
Because the Snowpark library is included on Snowflake, exclude it from the JAR file by specifying that the dependency is
libraryDependencies += "com.snowflake" % "snowpark" % "1.1.0" % "provided"
Change to the directory for your project (e.g.
hello-snowpark), and run the following command:
If you encounter the error
Not a valid command: assembly,
Not a valid project ID: assembly, or
Not a valid key: assembly, make sure that the
plugins.sbtfile is in the subdirectory named
project/(as mentioned in step 1).
This command creates a JAR file in the following location: