The document discusses using Bazel for building Scala projects. It begins with an overview of Bazel and how it uses small targets and rules to build code more incrementally and in parallel compared to tools like Maven and Gradle. It then covers the rules_scala plugin, which provides rules for compiling Scala code into JARs and running tests. Features of rules_scala like dependency management and support for multiple Scala versions are also summarized. Overall the document promotes Bazel and rules_scala as enabling significantly faster builds of large Scala codebases.
%in Midrand+277-882-255-28 abortion pills for sale in midrand
Building scala with bazel
1. Natan Silnitsky
Software dev in CI team, Wix.com
Building Scala with Bazel
natans@wix.com twitter@NSilnitsky linkedin/natansilnitsky github.com/natansil
7. In Bazel
You control the level of granularity
to build.
scala_project
├── WORKSPACE
└── src
└── main
└── scala
└── com
├── example
│ ├── A.scala
│ ├── B.scala
│ └── C.scala
└── example2
├── D.scala
├── E.scala
└── F.scala
8. The basic build unit is
called a target
scala_project
├── WORKSPACE
└── src
└── main
└── scala
└── com
├── example
│ ├── A.scala
│ ├── B.scala
│ ├── BUILD
│ └── C.scala
└── example2
├── D.scala
├── E.scala
└── F.scala
Target
Targets are instances
of rules.
9. A RULE
f(A,B,C)f( )
Source files
env’ variables
dependencies
A
B
C
scala library | C++ binary | python test | shell script | many many more...
wix
35. FEATURES
SCALA TOOLCHAIN
Globally set scala configuration
scala_toolchain(
name = "my_toolchain_impl",
scalacopts = ["-Ywarn-unused"],
unused_dependency_checker_mode = "off",
visibility = ["//visibility:public"]
)
36. --unused_dependency_checker_mode=WARN|ERROR
...
error: Target '//some_package:unused_dep' is specified as a dependency to //path/to:foo but isn't used, please
remove it from the deps.
You can use the following buildozer command:
buildozer 'remove deps //some_package:unused_dep' //path/to:foo
FEATURES
RUN THE SCALA COMPILER WITH FLAGS
DEPENDENCY MGMT
foo
B unused
37. --strict_java_deps=WARN|ERROR
...
Target '@cats//jar' is used but isn't explicitly declared, please add it to the deps.
You can use the following buildozer command:
buildozer 'add deps @cats//jar' //path/to:foo
FEATURES
RUN THE SCALA COMPILER WITH FLAGS
DEPENDENCY MGMT
foo
specs2
cats
38. --strict_java_deps=WARN|ERROR
...
Target '@cats//jar' is used but isn't explicitly declared, please add it to the deps.
You can use the following buildozer command:
buildozer 'add deps @cats//jar' //path/to:foo
Based on Jason Zaugg’s Classpath Shrinker plugin
FEATURES
RUN THE SCALA COMPILER WITH FLAGS
DEPENDENCY MGMT
foo
specs2
cats
39. Automatically fix dependencies in BUILD files
by parsing errors from bazel build result log + index server.
FEATURES
OSS SOON
DepFixer
Internal
JARs
External
JARs
Build result log
40. Automatically fix dependencies in BUILD files
by parsing errors from bazel build result log (+ index server.)
Inspired by Pants
FEATURES
OSS SOON
DepFixer
Internal
JARs
External
JARs
Build result log
42. build --strategy=Scalac=worker
FEATURES
FOR A ‘WARM’ SCALA COMPILER
PERSISTENT WORKERS
rules_scala annex (alternative plugin) has a persistent worker
too that uses zinc - stateful incremental compiler.
github.com/higherkindness/rules_scala
scalac
Workers
44. Default is Scala 2.11.12.
For other versions:
scala_repositories(("2.12.6", {
"scala_compiler": "3023b07cc02f2b0217b2c04f8e636b396130b3a8544a8dfad498a19c3e57a863",
"scala_library": "f81d7144f0ce1b8123335b72ba39003c4be2870767aca15dd0888ba3dab65e98",
"scala_reflect": "ffa70d522fc9f9deec14358aa674e6dd75c9dfa39d4668ef15bb52f002ce99fa"
}))
FEATURES
CROSS-VERSION SUPPORT
BY THE END OF 2019
46. Migration Stories
How to successfully migrate to Bazel - My talk @Devoxx UA 2018
Migrating to Bazel? 5 crucial questions... - My Blog Series on Medium
Speedy Scala Builds with Bazel at Databricks