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.

  1. In the directory containing your build.sbt file, create a file named plugins.sbt in the project/ subdirectory.

    For example, if the directory containing your build.sbt file is hello-snowpark/, create the file hello-snowpark/project/plugins.sbt:

    hello-snowpark/
                 |__ build.sbt
                 |__ project/
                           |__plugins.sbt
    
  2. In the plugins.sbt file, add the following line:

    addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
    
  3. 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.

  4. 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).

  5. 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, or Not a valid key: assembly, make sure that the plugins.sbt file is in the subdirectory named project/ (as mentioned in step 1).

    This command creates a JAR file in the following location:

    target/scala-<version>/<project-name>-assembly-1.0.jar