# rules_scala **Repository Path**: mirrors_benjaminp/rules_scala ## Basic Information - **Project Name**: rules_scala - **Description**: Scala rules for Bazel - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-08 - **Last Updated**: 2025-09-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Scala Rules for Bazel [](https://travis-ci.org/bazelbuild/rules_scala) [](https://ci.bazel.io/job/rules_scala)
## Overview This rule is used for building [Scala][scala] projects with Bazel. There are currently four rules, `scala_library`, `scala_macro_library`, `scala_binary` and `scala_test`. ## Getting started In order to use `scala_library`, `scala_macro_library`, and `scala_binary`, you must have bazel 0.5.3 or later and add the following to your WORKSPACE file: ```python rules_scala_version="5cdae2f034581a05e23c3473613b409de5978833" # update this as needed http_archive( name = "io_bazel_rules_scala", url = "https://github.com/bazelbuild/rules_scala/archive/%s.zip"%rules_scala_version, type = "zip", strip_prefix= "rules_scala-%s" % rules_scala_version ) load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories") scala_repositories() ``` To use a particular tag, use the tagged number in `tag = ` and omit the `commit` attribute. Note that these plugins are still evolving quickly, as is bazel, so you may need to select the version most appropriate for you. Then in your BUILD file just add the following so the rules will be available: ```python load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library", "scala_binary", "scala_test") ``` You may wish to have these rules loaded by default using bazel's prelude. You can add the above to the file `tools/build_rules/prelude_bazel` in your repo (don't forget to have a, possibly empty, BUILD file there) and then it will be automatically prepended to every BUILD file in the workspace. To run with a persistent worker (much faster), you need to add ``` build --strategy=Scalac=worker test --strategy=Scalac=worker ``` to your command line, or to enable by default for building/testing add it to your .bazelrc. [scala]: http://www.scala-lang.org/ ## scala\_library / scala\_macro_library ```python scala_library(name, srcs, deps, runtime_deps, exports, data, main_class, resources, resource_strip_prefix, scalacopts, jvm_flags, scalac_jvm_flags, javac_jvm_flags) scala_macro_library(name, srcs, deps, runtime_deps, exports, data, main_class, resources, resource_strip_prefix, scalacopts, jvm_flags, scalac_jvm_flags, javac_jvm_flags) ``` `scala_library` generates a `.jar` file from `.scala` source files. This rule also creates an interface jar to avoid recompiling downstream targets unless their interface changes. `scala_macro_library` generates a `.jar` file from `.scala` source files when they contain macros. For macros, there are no interface jars because the macro code is executed at compile time. For best performance, you want very granular targets until such time as the zinc incremental compiler can be supported. In order to make a java rule use this jar file, use the `java_import` rule.Attributes | |
---|---|
name |
A unique name for this target |
srcs |
List of Scala |
deps |
List of other libraries to linked to this library target |
runtime_deps |
List of other libraries to put on the classpath only at runtime. This is rarely needed in Scala. |
exports |
List of targets to add to the dependencies of those that depend on this target. Similar to the `java_library` parameter of the same name. Use this sparingly as it weakens the precision of the build graph. |
data |
List of files needed by this rule at runtime. |
main_class |
Name of class with main() method to use as an entry point
The value of this attribute is a class name, not a source file. The
class must be available at runtime: it may be compiled by this rule
(from |
resources |
A list of data files to be included in the JAR. |
resource_strip_prefix |
The path prefix to strip from Java resources. If specified, this path prefix is stripped from every file in the `resources` attribute. It is an error for a resource file not to be under this directory. |
scalacopts |
Extra compiler options for this library to be passed to scalac. Subject to Make variable substitution and Bourne shell tokenization. |
jvm_flags |
Deprecated, superseded by scalac_jvm_flags and javac_jvm_flags. Is not used and is kept as backwards compatibility for the near future. Effectively jvm_flags is now an executable target attribute only. |
scalac_jvm_flags |
List of JVM flags to be passed to scalac after the
|
javac_jvm_flags |
List of JVM flags to be passed to javac after the
|
Attributes | |
---|---|
name |
A unique name for this target |
srcs |
List of Scala |
deps |
List of other libraries to linked to this binary target |
runtime_deps |
List of other libraries to put on the classpath only at runtime. This is rarely needed in Scala. |
data |
List of files needed by this rule at runtime. |
main_class |
Name of class with main() method to use as an entry point
The value of this attribute is a class name, not a source file. The
class must be available at runtime: it may be compiled by this rule
(from |
resources |
A list of data files to be included in the JAR. |
resource_strip_prefix |
The path prefix to strip from Java resources. If specified, this path prefix is stripped from every file in the `resources` attribute. It is an error for a resource file not to be under this directory. |
scalacopts |
Extra compiler options for this binary to be passed to scalac. Subject to Make variable substitution and Bourne shell tokenization. |
jvm_flags |
List of JVM flags to be passed to the executing JVM. Subject to Make variable substitution and Bourne shell tokenization. |
scalac_jvm_flags |
List of JVM flags to be passed to scalac after the
|
javac_jvm_flags |
List of JVM flags to be passed to javac after the
|
Attributes | |
---|---|
name |
A unique name for this target |
srcs |
List of Thrift |
deps |
List of other thrift dependencies that this thrift depends on. |
absolute_prefix |
This string acts as a wildcard expression of the form *`string_value` that is removed from the start of the path. Example: thrift is at `a/b/c/d/e/A.thrift` , prefix of `b/c/d`. Will mean other thrift targets can refer to this thrift at `e/A.thrift`. |
absolute_prefixes |
Each of these strings acts as a wildcard expression of the form |
Attributes | |
---|---|
name |
A unique name for this target |
deps |
List of dependencies for this target. Must either be of type |
with_grpc |
Enables generation of grpc service bindings for services defined in |
with_java |
Enables generation of converters to and from java protobuf bindings. If you set this to |
with_flat_package |
When true, ScalaPB will not append the protofile base name to the package name |
with_single_line_to_string |
Enables generation of |