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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsThe JVM library dependencies.List of labelsoptional[]
srcsThe source Scala and Java files (and -sources.jar .srcjar -src.jar files of those).List of labelsrequired
dataThe additional runtime files needed by this library.List of labelsoptional[]
resourcesThe files to include as classpath resources.List of labelsoptional[]
deps_checker_labelThe 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.
Stringoptional""
deps_unused_whitelistThe JVM library dependencies to always consider unused for scala_deps_direct checks.List of labelsoptional[]
deps_used_whitelistThe JVM library dependencies to always consider used for scala_deps_used checks.List of labelsoptional[]
javacoptsThe Javac options.List of stringsoptional[]
jvm_flagsThe JVM runtime flags.List of stringsoptional[]
main_classThe main class. If not provided, it will be inferred by its type signature.Stringoptional""
pluginsThe Scalac plugins.List of labelsoptional[]
resource_jarsThe JARs to merge into the output JAR.List of labelsoptional[]
resource_strip_prefixThe path prefix to strip from classpath resources.Stringoptional""
runtime_depsThe JVM runtime-only library dependencies.List of labelsoptional[]
scala_versionThe Scala version to use, e.g., '3', '2.13', '3.3.7', or '_' for prefixed versions.Stringoptional""
scalacoptsThe Scalac options.List of stringsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsLibraries used by this one.List of labelsoptional[]
deps_checker_labelThe 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.
Stringoptional""
exportsLibraries made available by this one. See https://bazel.build/versions/6.0.0/reference/be/java#java_library.exports.List of labelsoptional[]
jarsJAR files to include in this library.List of labelsoptional[]
neverlinkSet this to True to exclude this library from the runtime classpath (i.e. if it should only be used at compile-time).BooleanoptionalFalse
runtime_depsLibraries used by this one, but which aren't referenced explicitly and need only be available at runtime.List of labelsoptional[]
srcjarThe source JAR for this library.LabeloptionalNone

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsThe JVM library dependencies.List of labelsoptional[]
srcsThe source Scala and Java files (and -sources.jar .srcjar -src.jar files of those).List of labelsrequired
dataThe additional runtime files needed by this library.List of labelsoptional[]
resourcesThe files to include as classpath resources.List of labelsoptional[]
deps_checker_labelThe 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.
Stringoptional""
deps_unused_whitelistThe JVM library dependencies to always consider unused for scala_deps_direct checks.List of labelsoptional[]
deps_used_whitelistThe JVM library dependencies to always consider used for scala_deps_used checks.List of labelsoptional[]
exportsThe JVM libraries to add as dependencies to any libraries dependent on this one.List of labelsoptional[]
javacoptsThe Javac options.List of stringsoptional[]
macroWhether this library provides macros.BooleanoptionalFalse
neverlinkWhether this library should be excluded at runtime.BooleanoptionalFalse
pluginsThe Scalac plugins.List of labelsoptional[]
resource_jarsThe JARs to merge into the output JAR.List of labelsoptional[]
resource_strip_prefixThe path prefix to strip from classpath resources.Stringoptional""
runtime_depsThe JVM runtime-only library dependencies.List of labelsoptional[]
scala_versionThe Scala version to use, e.g., '3', '2.13', '3.3.7', or '_' for prefixed versions.Stringoptional""
scalacoptsThe Scalac options.List of stringsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsDependencies that should be made available to the REPL.List of labelsoptional[]
dataThe additional runtime files needed by this REPL.List of labelsoptional[]
jvm_flagsThe JVM runtime flags.List of stringsoptional[]
scala_versionThe Scala version to use, e.g., '3', '2.13', '3.3.7', or '_' for prefixed versions.Stringoptional""
scalacoptsOptions to pass to scalac.List of stringsoptional[]

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

More Info

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsThe JVM library dependencies.List of labelsoptional[]
srcsThe source Scala and Java files (and -sources.jar .srcjar -src.jar files of those).List of labelsrequired
dataThe additional runtime files needed by this library.List of labelsoptional[]
resourcesThe files to include as classpath resources.List of labelsoptional[]
deps_checker_labelThe 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.
Stringoptional""
deps_unused_whitelistThe JVM library dependencies to always consider unused for scala_deps_direct checks.List of labelsoptional[]
deps_used_whitelistThe JVM library dependencies to always consider used for scala_deps_used checks.List of labelsoptional[]
frameworksThe list of test frameworks to check for. These should conform to the sbt test interface (https://github.com/sbt/test-interface).List of stringsoptional["org.scalatest.tools.Framework", "org.scalacheck.ScalaCheckFramework", "org.specs2.runner.Specs2Framework", "minitest.runner.Framework", "utest.runner.Framework", "com.novocode.junit.JUnitFramework"]
isolationThe isolation level to applyStringoptional"none"
javacoptsThe Javac options.List of stringsoptional[]
jvm_flagsThe JVM runtime flags.List of stringsoptional[]
pluginsThe Scalac plugins.List of labelsoptional[]
resource_jarsThe JARs to merge into the output JAR.List of labelsoptional[]
resource_strip_prefixThe path prefix to strip from classpath resources.Stringoptional""
runner-Labeloptional"@rules_scala_annex//src/main/scala/higherkindness/rules_scala/workers/zinc/test"
runtime_depsThe JVM runtime-only library dependencies.List of labelsoptional[]
scala_versionThe Scala version to use, e.g., '3', '2.13', '3.3.7', or '_' for prefixed versions.Stringoptional""
scalacoptsOptions to pass to scalac.List of stringsoptional[]
sequentialWhether to run test classes sequentially. If false, they'll be run concurrently.BooleanoptionalFalse
shared_depsIf isolation is "classloader", the list of deps to keep loaded between testsList of labelsoptional[]
subprocess_runner-Labeloptional"@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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsDependencies that should be made available to the Scaladoc tool. These may include libraries referenced in Scaladoc or public signatures.List of labelsoptional[]
srcsSources from which to generate Scaladoc. These may include *.java files, *.scala files, and source JARs.List of labelsoptional[]
compiler_depsJVM targets that should be included on the compile classpath.List of labelsoptional[]
scala_versionThe Scala version to use, e.g., '3', '2.13', '3.3.7', or '_' for prefixed versions.Stringoptional""
scalacoptsOptions to pass to scalac.List of stringsoptional[]
titleThe name of the project. If none is provided, the target label will be used.Stringoptional""

make_scala_binary

load("@rules_scala_annex//rules:scala.bzl", "make_scala_binary")

make_scala_binary(*extras)

PARAMETERS

NameDescriptionDefault Value
extras

-

none

make_scala_library

load("@rules_scala_annex//rules:scala.bzl", "make_scala_library")

make_scala_library(*extras)

PARAMETERS

NameDescriptionDefault Value
extras

-

none

make_scala_test

load("@rules_scala_annex//rules:scala.bzl", "make_scala_test")

make_scala_test(*extras)

PARAMETERS

NameDescriptionDefault Value
extras

-

none