scala_import

February 28, 2025 · View on GitHub

scala_import(
    name,
    jars,
    deps,
    runtime_deps,
    exports,
    neverlink,
    srcjar,
    stamp,
)

scala_import enables the use of precompiled Scala .jar files as dependencies for other Scala rules like scala_library, similar to java_import from Java rules.

This rule reimplements java_import without support for ijars, which break Scala macros. Generally, ijars don’t help much for external dependencies, which rarely change.

The jar's compile MANIFEST.MF is stamped with a Target-Label attribute for dependency tracking reporting.

Configuring stamping behavior

This behaviour can be changed per scala_import target with an attribute or globally with a setting:

bazel build //my:target --@rules_scala//scala/settings:stamp_scala_import=False

Attributes

Attribute nameDescription
nameName, required
A unique name for this target.
jarsList of labels, required
List of .jar files to import, usually in //external. In practice, this usually corresponds to one jar.
depsList of labels, optional
Compile time dependencies that were used to create the jar.
runtime_depsList of labels, optional
Runtime dependencies that are needed for this library.
exportsList of labels, optional
List of targets to add to the dependencies of those that depend on this target.
neverlinkboolean, optional (default False)
If true only use this library for compilation and not at runtime.
srcjarLabel, optional
The source jar that was used to create the jar.
stampLabel, optional
Setting to control Target-Label stamping into compile jar Manifest
Default value is @rules_scala//scala/settings:stamp_scala_import