scala.md
July 29, 2026 · View on GitHub
scala_binary
load("@rules_scala_annex//rules:scala.bzl", "scala_binary")
scala_binary(name, deps, srcs, data, resources, deps_checker_label, deps_unused_whitelist,
deps_used_whitelist, javacopts, jvm_flags, main_class, plugins, resource_jars,
resource_strip_prefix, runtime_deps, scala_version, scalacopts)
Compiles and links a Scala JVM executable.
Produces the following implicit outputs:
<name>_deploy.jar: a single jar that contains all the necessary information to run the program<name>.jar: a jar file that contains the class files produced from the sources<name>-bin: the script that's used to run the program in conjunction with the generated runfiles
To run the program: bazel run <target>
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | The JVM library dependencies. | List of labels | optional | [] |
| srcs | The source Scala and Java files (and -sources.jar .srcjar -src.jar files of those). | List of labels | required | |
| data | The additional runtime files needed by this library. | List of labels | optional | [] |
| resources | The files to include as classpath resources. | List of labels | optional | [] |
| deps_checker_label | The label to identify this target in the output of the dependency checker. By default, this is just the label of the target. But sometimes—for example, when overriding an artifact with rules_jvm_external to point to your own, or defining an alias to target—you want the dependency checker to suggest you add or remove a different label as a dependency. In that case, you can set this attribute to that label. | String | optional | "" |
| deps_unused_whitelist | The JVM library dependencies to always consider unused for scala_deps_direct checks. | List of labels | optional | [] |
| deps_used_whitelist | The JVM library dependencies to always consider used for scala_deps_used checks. | List of labels | optional | [] |
| javacopts | The Javac options. | List of strings | optional | [] |
| jvm_flags | The JVM runtime flags. | List of strings | optional | [] |
| main_class | The main class. If not provided, it will be inferred by its type signature. | String | optional | "" |
| plugins | The Scalac plugins. | List of labels | optional | [] |
| resource_jars | The JARs to merge into the output JAR. | List of labels | optional | [] |
| resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | "" |
| runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | [] |
| scala_version | The Scala version to use, e.g., '3', '2.13', '3.3.7', or ' | String | optional | "" |
| scalacopts | The Scalac options. | List of strings | optional | [] |
scala_import
load("@rules_scala_annex//rules:scala.bzl", "scala_import")
scala_import(name, deps, deps_checker_label, exports, jars, neverlink, runtime_deps, srcjar)
Creates a Scala JVM library.
Use this only for libraries with macros. Otherwise, use java_import.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Libraries used by this one. | List of labels | optional | [] |
| deps_checker_label | The label to identify this target in the output of the dependency checker. By default, this is just the label of the target. But sometimes—for example, when overriding an artifact with rules_jvm_external to point to your own, or defining an alias to target—you want the dependency checker to suggest you add or remove a different label as a dependency. In that case, you can set this attribute to that label. | String | optional | "" |
| exports | Libraries made available by this one. See https://bazel.build/versions/6.0.0/reference/be/java#java_library.exports. | List of labels | optional | [] |
| jars | JAR files to include in this library. | List of labels | optional | [] |
| neverlink | Set this to True to exclude this library from the runtime classpath (i.e. if it should only be used at compile-time). | Boolean | optional | False |
| runtime_deps | Libraries used by this one, but which aren't referenced explicitly and need only be available at runtime. | List of labels | optional | [] |
| srcjar | The source JAR for this library. | Label | optional | None |
scala_library
load("@rules_scala_annex//rules:scala.bzl", "scala_library")
scala_library(name, deps, srcs, data, resources, deps_checker_label, deps_unused_whitelist,
deps_used_whitelist, exports, javacopts, macro, neverlink, plugins, resource_jars,
resource_strip_prefix, runtime_deps, scala_version, scalacopts)
Compiles a Scala JVM library.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | The JVM library dependencies. | List of labels | optional | [] |
| srcs | The source Scala and Java files (and -sources.jar .srcjar -src.jar files of those). | List of labels | required | |
| data | The additional runtime files needed by this library. | List of labels | optional | [] |
| resources | The files to include as classpath resources. | List of labels | optional | [] |
| deps_checker_label | The label to identify this target in the output of the dependency checker. By default, this is just the label of the target. But sometimes—for example, when overriding an artifact with rules_jvm_external to point to your own, or defining an alias to target—you want the dependency checker to suggest you add or remove a different label as a dependency. In that case, you can set this attribute to that label. | String | optional | "" |
| deps_unused_whitelist | The JVM library dependencies to always consider unused for scala_deps_direct checks. | List of labels | optional | [] |
| deps_used_whitelist | The JVM library dependencies to always consider used for scala_deps_used checks. | List of labels | optional | [] |
| exports | The JVM libraries to add as dependencies to any libraries dependent on this one. | List of labels | optional | [] |
| javacopts | The Javac options. | List of strings | optional | [] |
| macro | Whether this library provides macros. | Boolean | optional | False |
| neverlink | Whether this library should be excluded at runtime. | Boolean | optional | False |
| plugins | The Scalac plugins. | List of labels | optional | [] |
| resource_jars | The JARs to merge into the output JAR. | List of labels | optional | [] |
| resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | "" |
| runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | [] |
| scala_version | The Scala version to use, e.g., '3', '2.13', '3.3.7', or ' | String | optional | "" |
| scalacopts | The Scalac options. | List of strings | optional | [] |
scala_repl
load("@rules_scala_annex//rules:scala.bzl", "scala_repl")
scala_repl(name, deps, data, jvm_flags, scala_version, scalacopts)
Launches a REPL with all given dependencies available.
To run: bazel run <target>
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Dependencies that should be made available to the REPL. | List of labels | optional | [] |
| data | The additional runtime files needed by this REPL. | List of labels | optional | [] |
| jvm_flags | The JVM runtime flags. | List of strings | optional | [] |
| scala_version | The Scala version to use, e.g., '3', '2.13', '3.3.7', or ' | String | optional | "" |
| scalacopts | Options to pass to scalac. | List of strings | optional | [] |
scala_test
load("@rules_scala_annex//rules:scala.bzl", "scala_test")
scala_test(name, deps, srcs, data, resources, deps_checker_label, deps_unused_whitelist,
deps_used_whitelist, frameworks, isolation, javacopts, jvm_flags, plugins, resource_jars,
resource_strip_prefix, runner, runtime_deps, scala_version, scalacopts, sequential,
shared_deps, subprocess_runner)
Compiles and links a collection of Scala tests.
To buid and run all tests: bazel test <target>
To build and run a specific test: bazel test <target> --test_filter=<filter_expression>
(Note: the syntax of the <filter_expression> varies by test framework, and not all test frameworks support the test_filter option at this time.)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | The JVM library dependencies. | List of labels | optional | [] |
| srcs | The source Scala and Java files (and -sources.jar .srcjar -src.jar files of those). | List of labels | required | |
| data | The additional runtime files needed by this library. | List of labels | optional | [] |
| resources | The files to include as classpath resources. | List of labels | optional | [] |
| deps_checker_label | The label to identify this target in the output of the dependency checker. By default, this is just the label of the target. But sometimes—for example, when overriding an artifact with rules_jvm_external to point to your own, or defining an alias to target—you want the dependency checker to suggest you add or remove a different label as a dependency. In that case, you can set this attribute to that label. | String | optional | "" |
| deps_unused_whitelist | The JVM library dependencies to always consider unused for scala_deps_direct checks. | List of labels | optional | [] |
| deps_used_whitelist | The JVM library dependencies to always consider used for scala_deps_used checks. | List of labels | optional | [] |
| frameworks | The list of test frameworks to check for. These should conform to the sbt test interface (https://github.com/sbt/test-interface). | List of strings | optional | ["org.scalatest.tools.Framework", "org.scalacheck.ScalaCheckFramework", "org.specs2.runner.Specs2Framework", "minitest.runner.Framework", "utest.runner.Framework", "com.novocode.junit.JUnitFramework"] |
| isolation | The isolation level to apply | String | optional | "none" |
| javacopts | The Javac options. | List of strings | optional | [] |
| jvm_flags | The JVM runtime flags. | List of strings | optional | [] |
| plugins | The Scalac plugins. | List of labels | optional | [] |
| resource_jars | The JARs to merge into the output JAR. | List of labels | optional | [] |
| resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | "" |
| runner | - | Label | optional | "@rules_scala_annex//src/main/scala/higherkindness/rules_scala/workers/zinc/test" |
| runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | [] |
| scala_version | The Scala version to use, e.g., '3', '2.13', '3.3.7', or ' | String | optional | "" |
| scalacopts | Options to pass to scalac. | List of strings | optional | [] |
| sequential | Whether to run test classes sequentially. If false, they'll be run concurrently. | Boolean | optional | False |
| shared_deps | If isolation is "classloader", the list of deps to keep loaded between tests | List of labels | optional | [] |
| subprocess_runner | - | Label | optional | "@rules_scala_annex//src/main/scala/higherkindness/rules_scala/common/sbt-testing:subprocess" |
scaladoc
load("@rules_scala_annex//rules:scala.bzl", "scaladoc")
scaladoc(name, deps, srcs, compiler_deps, scala_version, scalacopts, title)
Generates Scaladoc.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Dependencies that should be made available to the Scaladoc tool. These may include libraries referenced in Scaladoc or public signatures. | List of labels | optional | [] |
| srcs | Sources from which to generate Scaladoc. These may include *.java files, *.scala files, and source JARs. | List of labels | optional | [] |
| compiler_deps | JVM targets that should be included on the compile classpath. | List of labels | optional | [] |
| scala_version | The Scala version to use, e.g., '3', '2.13', '3.3.7', or ' | String | optional | "" |
| scalacopts | Options to pass to scalac. | List of strings | optional | [] |
| title | The name of the project. If none is provided, the target label will be used. | String | optional | "" |
make_scala_binary
load("@rules_scala_annex//rules:scala.bzl", "make_scala_binary")
make_scala_binary(*extras)
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| extras | - | none |
make_scala_library
load("@rules_scala_annex//rules:scala.bzl", "make_scala_library")
make_scala_library(*extras)
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| extras | - | none |
make_scala_test
load("@rules_scala_annex//rules:scala.bzl", "make_scala_test")
make_scala_test(*extras)
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| extras | - | none |