@@ -9,7 +9,7 @@ for the [Bazel build system](https://bazel.build).
99- HTML, text, XML, Markdown, and SARIF reports;
1010- [ plugins] ( https://detekt.dev/docs/extensions/extensions/ ) ;
1111- customizable Detekt version and JVM flags;
12- - [ persistent workers ] ( https://blog.bazel.build/2015/12/10/java-workers.html ) support;
12+ - [ type resolution ] ( https://detekt.dev/docs/gettingstarted/type-resolution/ ) with JVM and Android classpath support;
1313- baseline generation via ` detekt_create_baseline ` ;
1414- configuration options via [ attributes] ( docs/attrs.md ) .
1515
@@ -127,15 +127,15 @@ and it supports standard Bazel test flags such as `--test_output=all`.
127127
128128### ` detekt ` vs ` detekt_test `
129129
130- | | ` detekt ` | ` detekt_test ` |
131- | ------------------- | ------------------------- | -------------------------------------- |
132- | Bazel rule type | build rule | test rule |
133- | Run with | ` bazel build ` | ` bazel test ` |
134- | Included in | ` bazel build //... ` | ` bazel test //... ` |
135- | Violation behaviour | build action fails | test fails; build action always passes |
136- | Text report | printed when action fails | printed to test output when test fails |
137- | Result caching | yes | yes |
138- | Bazel test flags | n/a | yes (` --test_output ` , etc.) |
130+ | | ` detekt ` | ` detekt_test ` |
131+ | ------------------- | ------------------------- | ----------------------------------------------------------------------- |
132+ | Bazel rule type | build rule | test rule |
133+ | Run with | ` bazel build ` | ` bazel test ` |
134+ | Included in | ` bazel build //... ` | ` bazel test //... ` |
135+ | Violation behavior | build action fails | test fails; build action always passes even if violations are present |
136+ | Text report | printed when action fails | printed to test output when test fails |
137+ | Result caching | yes | yes |
138+ | Bazel test flags | n/a | yes (` --test_output ` , etc.) |
139139
140140Use ` detekt ` when you want violations to block builds the same way a compiler error does. Use
141141` detekt_test ` when you want Detekt to run alongside your test suite and report results through
@@ -177,8 +177,9 @@ detekt_test(
177177
178178### Configuration Options
179179
180- All three rules share the same configuration options. In addition to ` srcs ` , ` cfgs ` , ` baseline ` , ` plugins ` ,
181- and report options, most attributes correspond directly to
180+ All three rules share the same configuration options. In addition to ` srcs ` , ` deps ` , ` cfgs ` ,
181+ ` baseline ` , ` plugins ` , ` enable_type_resolution ` , ` is_android ` , and report options, most attributes
182+ correspond directly to
182183[ Detekt CLI flags] ( https://detekt.dev/docs/1.23.8/gettingstarted/cli/#use-the-cli ) and pass them
183184through when explicitly set.
184185
@@ -187,7 +188,7 @@ More information can be found in the [attributes](docs/attrs.md).
187188### Reports
188189
189190A plain-text report (` {name}_detekt_report.txt ` ) is ** always** generated. Other report formats are
190- available for opt-in via configuration options. .
191+ available for opt-in via attributes .
191192
192193## Advanced Configuration
193194
@@ -207,7 +208,7 @@ detekt.detekt_version(
207208use_repo(detekt, " detekt_cli_all" )
208209```
209210
210- To download Detekt from a custom location (e.g. an internal mirror), use the ` url_templates ` parameter:
211+ To download Detekt from a custom location (e.g., an internal mirror), use the ` url_templates ` parameter:
211212
212213``` python
213214detekt = use_extension(" @rules_detekt//detekt:extensions.bzl" , " detekt" )
@@ -252,17 +253,27 @@ rules_detekt_dependencies(
252253
253254Each template may contain ` {version} ` which will be replaced with the version string.
254255
255- ### JVM Flags
256+ ### Toolchain
257+
258+ The detekt toolchain controls JVM flags, the JVM bytecode target version, and the Kotlin language
259+ version compatibility. The defaults are:
260+
261+ | Setting | Default |
262+ | ------------------ | -------- |
263+ | ` jvm_flags ` | ` -Xms16m -Xmx128m ` |
264+ | ` jvm_target ` | ` 1.8 ` |
265+ | ` language_version ` | ` 2.0 ` |
256266
257- The default toolchain uses ` -Xms16m -Xmx128m ` . To customize JVM flags, define your own toolchain
258- in a ` BUILD ` file:
267+ To override any of these, define a custom toolchain in a ` BUILD ` file:
259268
260269``` python
261270load(" @rules_detekt//detekt:toolchain.bzl" , " detekt_toolchain" )
262271
263272detekt_toolchain(
264273 name = " my_detekt_toolchain_impl" ,
265274 jvm_flags = [" -Xms16m" , " -Xmx512m" ],
275+ jvm_target = " 11" ,
276+ language_version = " 1.9" ,
266277)
267278
268279toolchain(
@@ -354,49 +365,45 @@ detekt_test(
354365)
355366```
356367
357- ### JVM Target
358-
359- Use ` jvm_target ` to set the JVM bytecode target version that matches what was used during compilation.
360- This defaults to ` 1.8 ` if not explicitly set:
368+ ### Type Resolution
361369
362- ``` python
363- detekt_test(
364- name = " my_detekt" ,
365- srcs = glob([" src/main/kotlin/**/*.kt" ]),
366- jvm_target = " 11" ,
367- )
368- ```
370+ Type resolution enables more advanced static analysis by giving Detekt access to the full
371+ compilation classpath — including return types, nullability, and symbol information. Rules
372+ requiring it are annotated with ` @RequiresFullAnalysis ` in Detekt's source.
369373
370- ### Language Version
374+ Type resolution is ** disabled by default** (` enable_type_resolution = False ` ), meaning only
375+ syntax-based rules are applied and no classpath is passed to Detekt.
371376
372- Detekt will report errors for any language features introduced after the specified version if
373- ` language_version ` is specified. When unset, no compatibility restriction is applied:
377+ To enable type resolution, set ` enable_type_resolution = True ` . When enabled, the appropriate
378+ bootclasspath (JDK or Android SDK) is always included. To also include your project's library
379+ dependencies on the classpath, pass them via ` deps ` :
374380
375381``` python
382+ load(" @rules_detekt//detekt:defs.bzl" , " detekt_test" )
383+
376384detekt_test(
377385 name = " my_detekt" ,
378386 srcs = glob([" src/main/kotlin/**/*.kt" ]),
379- language_version = " 2.0" ,
387+ enable_type_resolution = True ,
388+ deps = [" :my_library" ], # provides the classpath for type resolution
380389)
381390```
382391
383- ### Type Resolution
384-
385- Type resolution enables more advanced static analysis by giving Detekt access to the full compilation classpath,
386- including return types, nullability, and symbol information — capabilities that match those of the Kotlin compiler
387- itself. Rules requiring it are annotated with ` @RequiresFullAnalysis ` in Detekt's source.
388-
389- Use ` jvm_target ` and ` language_version ` to match the compilation settings of your project:
392+ For ** Android targets** , set ` is_android = True ` to include the Android SDK jar in the classpath:
390393
391394``` python
392395detekt_test(
393396 name = " my_detekt" ,
394397 srcs = glob([" src/main/kotlin/**/*.kt" ]),
395- jvm_target = " 11" ,
396- language_version = " 2.0" ,
398+ enable_type_resolution = True ,
399+ deps = [" :my_android_library" ],
400+ is_android = True ,
397401)
398402```
399403
404+ ` jvm_target ` and ` language_version ` are toolchain-level settings — see
405+ [ Toolchain] ( #toolchain ) for how to configure them.
406+
400407### Reports
401408
402409By default, Detekt generates a text report internally (used for console output). To export reports as build outputs,
0 commit comments