Packaging Scala Handler Code with SBT¶
If you are using SBT to build and package your code, you can use the sbt-assembly plugin to create a JAR file containing all of the dependencies.
In the directory containing your
build.sbt
file, create a file namedplugins.sbt
in theproject/
subdirectory.For example, if the directory containing your
build.sbt
file ishello-snowpark/
, create the filehello-snowpark/project/plugins.sbt
:hello-snowpark/ |__ build.sbt |__ project/ |__plugins.sbt
In the
plugins.sbt
file, add the following line:addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
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.sbt
file to resolve the dependencies. See Merge Strategy for details.In your
build.sbt
file, update the Snowpark library version to at least the minimum version required.libraryDependencies += "com.snowflake" % "snowpark" % "1.1.0" % "provided"
In addition, exclude the Snowpark library from the JAR file by specifying that the dependency is
"provided"
(as shown above).Change to the directory for your project (e.g.
hello-snowpark
), and run the following command:sbt assembly
Note
If you encounter the error
Not a valid command: assembly
,Not a valid project ID: assembly
, orNot a valid key: assembly
, make sure that theplugins.sbt
file is in the subdirectory namedproject/
(as mentioned in step 1).This command creates a JAR file in the following location:
target/scala-<version>/<project-name>-assembly-1.0.jar