You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You first need to add the following to your WORKSPACE file:
475
475
@@ -543,6 +543,30 @@ generated by the [ScalaPB compiler](https://github.com/scalapb/ScalaPB).
543
543
</tbody>
544
544
</table>
545
545
546
+
## [Experimental] Using strict-deps
547
+
Bazel pushes towards explicit and minimial dependencies to keep BUILD file higene and allow for targets to refactor their dependencies without fear of downstream breaking.
548
+
Currently rules_scala does this at the cost of having cryptic `scalac` errors when one mistakenly depends on a transitive dependency or, as more often the case for some, a transitive dependency is needed to [please scalac](https://github.com/scalacenter/advisoryboard/blob/master/proposals/009-improve-direct-dependency-experience.md) itself.
549
+
To learn more about the motivation of strict-deps itself you can visit this Bazel blog [post](https://blog.bazel.build/2017/06/28/sjd-unused_deps.html) on the subject.
550
+
551
+
To use it just add `--strict_java_deps=WARN|ERROR` to your `bazel` invocation.
552
+
In both cases of `WARN` or `ERROR` you will get the following text in the event of a violation:
553
+
```
554
+
...
555
+
Target '//some_package:transitive_dependency' is used but isn't explicitly declared, please add it to the deps.
Note that if you have `buildozer` installed you can just run the last line and have it automatically apply the fix for you.
560
+
561
+
**Caveats:**
562
+
<ul>
563
+
<li>Extra builds- when strict-deps is on the transitive dependencies are inputs to the compilation action which means you can potentially have more build triggers for changes the cross the ijar boundary </li>
564
+
<li>Label propagation- since label of targets are needed for the clear message and since it's not currently supported by JavaInfo from bazel we manually propagate it. This means that the error messages have a significantly lower grade if you don't use one of the scala rules or scala_import (since they don't propagate these labels)</li>
565
+
<li>javac outputs incorrect targets due to a problem we're tracing down. Practically we've noticed it's pretty trivial to understand the correct target (i.e. it's almost a formatting problem) </li>
566
+
</ul>
567
+
568
+
Note: Currently strict-deps is protected by a feature toggle but we're strongly considering making it the default behavior as `java_*` rules do.
0 commit comments