rules_kotlin
rules_kotlin copied to clipboard
Improve jdeps logic to find more explicit and implicit dependencies
Problem
Kotlin jdeps do not collect many direct and indirect dependencies that are required for compilation. These missing jdep found dependencies were discovered as Airbnb tests a "jdeps compile-time pruning" optimization which provides significant IntelliJ indexing, UI, and compilation performance benefits in our fork of the Bazel IntelliJ Plugin. See also https://github.com/bazelbuild/rules_kotlin/pull/1115 as @Bencodes and I unknowingly started looking at this issue at about the same time!
Solution
As a followup to https://github.com/bazelbuild/rules_kotlin/pull/1045, write test cases to repro missing deps found when compiling Airbnb's JVM monorepo, and then fix the underlying issues. Note that these fixes were made with very minimal knowledge of Kotlin compiler internals, so please suggest alternatives if there are better ways to collect these types. Thanks!
Test Plan:
- Wrote Kotlin and Java test cases to repro missing dependencies found in the Airbnb monorepo
- Updated Airbnb's minimal rules_kotlin fork to use the changes in this PR and the updated rules_kotlin fork has been successfully running in CI for over a week.
Appendix
For anyone interested in how we're planning to use jdeps pruning:
- We've been experimenting with using IntelliJ's incremental compiler to perform compilations after the initial Bazel sync.
- We use jdeps to prune the compile classpath, so that only the interface jars needed to compile the editable targets are added as IntelliJ libraries. For one of our large services, we see a 20x reduction in compile time jars (2000 -> 100). This reduction speeds up indexing, UI responsiveness, and incremental compilation speed (5s -> 1s).
- Using IntelliJ's incremental compiler with a jdeps pruned classpath has been 30-70x faster than "bazel build/test" for the same large service (30-70s -> 1s) on an M2 Mac. Note that we follow "1:1:1" and have a BUILD file in every Java/Kotlin/Scala package.