Skip to content

Commit 09989c0

Browse files
committed
Document validate_scala_version = False
Adds "Disabling Scala version validation when defining a custom Scala toolchain" under "Breaking changes in `rules_scala` 7.x" in `README.md`. Adds "Step 3 (optional)" under "Defining your own `scala_toolchain`" in `docs/scala_toolchain.md`. Prompted by: bazel-contrib#1710 (comment) Also fixes a typo and a broken link in `docs/scala_toolchain.md`.
1 parent a94e242 commit 09989c0

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,35 @@ In `WORKSPACE`, this `register_toolchains()` call must come before calling
711711
`scala_register_toolchains()` to ensure this toolchain takes precedence. The
712712
same exact call will also work in `MODULE.bazel`.
713713

714+
### Disabling Scala version validation when defining a custom Scala toolchain
715+
716+
When [defining a 'scala_toolchain()' using custom compiler JARs](
717+
docs/scala_toolchain.md#b-defining-your-own-scala_toolchain), while using
718+
`scala_toolchains()` to instantiate other builtin toolchains, set
719+
`validate_scala_version = False`:
720+
721+
```py
722+
# WORKSPACE
723+
scala_toolchains(
724+
validate_scala_version = False,
725+
# ...other toolchain parameters...
726+
)
727+
```
728+
729+
This differs from the previous API in two ways that avoided instantiating the
730+
default Scala compiler JAR repositories, and thus Scala version validation:
731+
732+
- Calling `scala_repositories(load_jar_deps = False)` would instantiate only
733+
other `rules_scala` dependency repos (`rules_java`, `protobuf`, etc.) and
734+
compiler source JAR repos.
735+
736+
- Calling `rules_scala_setup()` directly, instead of indirectly via
737+
`scala_repositories()`, instantiated the other dependency repositories only.
738+
739+
See ["Defining your own scala_toolchain > Step 3 (optional)" from
740+
docs/scala_toolchain.md](docs/scala_toolchain.md#step-3-optional) for futher
741+
details.
742+
714743
### Bzlmod configuration (coming soon!)
715744

716745
The upcoming Bzlmod implementation will funnel through the `scala_toolchains()`

docs/scala_toolchain.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ scala_toolchains()
2525
scala_register_toolchains()
2626
```
2727

28-
### B) Defining your own `scala_toolchain` requires 2 steps
28+
### B) Defining your own `scala_toolchain`
2929

3030
#### Step 1
3131

@@ -65,7 +65,7 @@ load("@rules_scala//scala:scala.bzl", "setup_scala_toolchain")
6565

6666
setup_scala_toolchain(
6767
name = "my_toolchain",
68-
# configure toolchain dependecies
68+
# configure toolchain dependencies
6969
parser_combinators_deps = [
7070
"@maven//:org_scala_lang_modules_scala_parser_combinators_2_12",
7171
],
@@ -101,6 +101,32 @@ Register your custom toolchain:
101101
register_toolchains("//toolchains:my_scala_toolchain")
102102
```
103103

104+
#### Step 3 (optional)
105+
106+
If you use `scala_toolchains()` to instantiate other builtin toolchains, set
107+
`validate_scala_version = False`:
108+
109+
```py
110+
# WORKSPACE
111+
scala_toolchains(
112+
validate_scala_version = False,
113+
# ...other toolchain parameters...
114+
)
115+
```
116+
117+
This prevents `rules_scala` from checking that the Scala versions specified via
118+
`scala_config` match the `scala_version` values from
119+
`third_party/repositories/scala_*.bzl`.
120+
121+
`scala_toolchains()` uses these `scala_*.bzl` files to instantiate dependency
122+
JAR repositories required by the builtin toolchains. It always instantiates a
123+
default Scala toolchain, along with its compiler JAR repositories, since [most
124+
users expect this behavior][1633-comment]. (As always, calling
125+
`register_toolchains()` on your own toolchain in `MODULE.bazel`, or before
126+
`scala_register_toolchains()` in `WORKSPACE`, overrides the builtin toolchain.)
127+
128+
[1633-comment]: https://github.com/bazelbuild/rules_scala/pull/1633#discussion_r1834378901
129+
104130
## Configuration options
105131

106132
The following attributes apply to both `scala_toolchain` and
@@ -168,7 +194,7 @@ The following attributes apply to both `scala_toolchain` and
168194
<td>
169195
<p><code>String; optional</code></p>
170196
<p>
171-
Enable unused dependency checking (see <a href="https://github.com/bazelbuild/rules_scala#experimental-unused-dependency-checking">Unused dependency checking</a>).
197+
Enable unused dependency checking (see <a href="./dependency-tracking.md#experimental-unused-dependency-checking">Unused dependency checking</a>).
172198
Possible values are: <code>off</code>, <code>warn</code> and <code>error</code>.
173199
</p>
174200
</td>

0 commit comments

Comments
 (0)