@@ -6,7 +6,7 @@ for the [Bazel build system](https://bazel.build).
66## Features
77
88- configuration and baseline files;
9- - HTML, text, XML, Markdown, and SARIF reports;
9+ - HTML, XML, Markdown, and SARIF reports;
1010- [ plugins] ( https://detekt.dev/docs/extensions/extensions/ ) ;
1111- customizable Detekt version and JVM flags;
1212- [ type resolution] ( https://detekt.dev/docs/gettingstarted/type-resolution/ ) with JVM and Android classpath support;
@@ -15,24 +15,25 @@ for the [Bazel build system](https://bazel.build).
1515
1616## Compatibility
1717
18- | ` bazel_rules_detekt ` | Default Detekt | Kotlin compiler | Max ` language_version ` | Min JDK | Max tested JDK | Bazel |
19- | ----------------------------------- | --------------- | --------------- | ---------------------- | ------- | -------------- | --------- |
20- | ** v0.8.1.9 – v0.8.1.13** _ (latest)_ | 1.23.8 | 2.0.21 | ` 2.0 ` | 8 | 21 | 9.x |
21- | v0.8.1.3 – v0.8.1.8 | 1.23.5 | 1.9.22 | ` 1.9 ` | 8 | 17 | 7.x – 9.x |
22- | v0.8.1 – v0.8.1.2 | 1.23.1 | 1.9.0 | ` 1.9 ` | 8 | 17 | 6.x |
23- | v0.7.0 | 1.22.0 | — | — | 8 | — | 5.x |
24- | v0.6.0 – v0.6.1 | 1.19.0 – 1.21.0 | — | — | 8 | — | 5.x |
25- | v0.4.0 – v0.5.0 | 1.15.0 | — | — | — | — | 4.x |
26- | v0.3.0 | 1.7.4 | — | — | — | — | 3.x |
27- | v0.1.0 – v0.2.0 | 1.2.0 | — | — | — | — | 1.x |
18+ > ** Breaking change:** ` bazel_rules_detekt ` v2.0+ requires ** Detekt 2.0 or later** . It is not compatible with Detekt 1.x. If you need Detekt 1.x support, use ` bazel_rules_detekt ` v0.8.x.
19+
20+ | ` bazel_rules_detekt ` | Default Detekt | Kotlin compiler | ` language_version ` | JDK | Bazel |
21+ | -----------------------------| --------------- | --------------- | ------------------- | ---------- | --------- |
22+ | ** v1.0-alpha.2** _ (latest)_ | 2.0.0-alpha.2 | 2.2.x | ` 1.0 ` – ` 2.3 ` | 8 – 21 | 9.x |
23+ | v0.8.1.9 – v0.8.1.13 | 1.23.8 | 2.0.21 | ` 1.0 ` – ` 2.0 ` | 8 – 21 | 9.x |
24+ | v0.8.1.3 – v0.8.1.8 | 1.23.5 | 1.9.22 | ` 1.0 ` – ` 1.9 ` | 8 – 17 | 7.x – 9.x |
25+ | v0.8.1 – v0.8.1.2 | 1.23.1 | 1.9.0 | ` 1.0 ` – ` 1.9 ` | 8 – 17 | 6.x |
26+ | v0.7.0 | 1.22.0 | — | — | 8+ | 5.x |
27+ | v0.6.0 – v0.6.1 | 1.19.0 – 1.21.0 | — | — | 8+ | 5.x |
28+ | v0.4.0 – v0.5.0 | 1.15.0 | — | — | — | 4.x |
29+ | v0.3.0 | 1.7.4 | — | — | — | 3.x |
30+ | v0.1.0 – v0.2.0 | 1.2.0 | — | — | — | 1.x |
2831
2932For detailed per-Detekt-version Kotlin and JDK compatibility, see the [ Detekt compatibility table] ( https://detekt.dev/docs/introduction/compatibility/ ) .
3033
3134> ** Note:** The Kotlin compiler bundled with Detekt determines which ` language_version ` values are valid — setting it higher than what the bundled compiler supports will cause Detekt to fail. The default Detekt version can always be overridden — see [ Detekt Version] ( #detekt-version ) .
3235
33- > ** Note:** Detekt 2.x is currently in alpha (targeting Kotlin 2.2+) and is not yet recommended for production use.
34-
35- > ** Note:** JDK 25 and above are ** not** supported with Detekt 1.23.x. The bundled Kotlin compiler performs a hard version check that fails on JDK 25+. This is resolved in the Detekt 2.x series.
36+ > ** Important:** Detekt 2.x is currently in alpha (targeting Kotlin 2.2+) and is not yet recommended for production use.
3637
3738### Bazel
3839
@@ -86,9 +87,9 @@ Once declared in the `WORKSPACE` or `MODULE.bazel` file, the rules can be loaded
8687
8788### ` detekt `
8889
89- ` detekt ` is a regular Bazel build rule. When Detekt finds violations , the ** build action itself
90+ ` detekt ` is a regular Bazel build rule. When Detekt reports findings , the ** build action itself
9091fails** , stopping ` bazel build ` immediately with an error. This makes it behave like a compiler
91- error — violations block the build.
92+ error — findings block the build.
9293
9394``` python
9495load(" @rules_detekt//detekt:defs.bzl" , " detekt" )
@@ -105,9 +106,9 @@ $ bazel build //mypackage:my_detekt
105106
106107### ` detekt_test `
107108
108- ` detekt_test ` is a Bazel test rule. The build action always succeeds (even when violations are
109- found ), and Bazel then runs a test script that reads the real Detekt exit code and prints findings
110- to the test output. Violations cause the ** test** to fail rather than the build action.
109+ ` detekt_test ` is a Bazel test rule. The build action always succeeds (even when findings are
110+ reported ), and Bazel then runs a test script that reads the real Detekt exit code and prints findings
111+ to the test output. Findings cause the ** test** to fail rather than the build action.
111112
112113``` python
113114load(" @rules_detekt//detekt:defs.bzl" , " detekt_test" )
@@ -132,20 +133,20 @@ and it supports standard Bazel test flags such as `--test_output=all`.
132133| Bazel rule type | build rule | test rule |
133134| Run with | ` bazel build ` | ` bazel test ` |
134135| 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 |
136+ | Finding behavior | build action fails | test fails; build action always passes even if findings are reported |
137+ | Console output | printed when action fails | printed to test output when test fails |
137138| Result caching | yes | yes |
138139| Bazel test flags | n/a | yes (` --test_output ` , etc.) |
139140
140- Use ` detekt ` when you want violations to block builds the same way a compiler error does. Use
141+ Use ` detekt ` when you want findings to block builds the same way a compiler error does. Use
141142` detekt_test ` when you want Detekt to run alongside your test suite and report results through
142143the test framework.
143144
144145### ` detekt_create_baseline `
145146
146147` detekt_create_baseline ` is an executable rule that generates or updates a
147148[ Detekt baseline] ( https://detekt.dev/docs/introduction/baseline/ ) file. The baseline suppresses
148- existing findings so that only new violations fail the build going forward.
149+ existing findings so that only new findings fail the build going forward.
149150
150151``` python
151152load(" @rules_detekt//detekt:defs.bzl" , " detekt_create_baseline" )
@@ -178,23 +179,22 @@ detekt_test(
178179### Configuration Options
179180
180181All 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+ ` baseline ` , ` plugins ` , ` analysis_mode ` , ` is_android ` , and report options, most attributes
182183correspond directly to
183- [ Detekt CLI flags] ( https://detekt.dev/docs/1.23.8/ gettingstarted/cli/#use-the-cli ) and pass them
184+ [ Detekt CLI flags] ( https://detekt.dev/docs/gettingstarted/cli/#use-the-cli ) and pass them
184185through when explicitly set.
185186
186187More information can be found in the [ attributes] ( docs/attrs.md ) .
187188
188189### Reports
189190
190- A plain-text report (` {name}_detekt_report.txt ` ) is ** always** generated. Other report formats are
191- available for opt-in via attributes.
191+ Findings are printed directly to the console. Report files can be enabled for export as build outputs via attributes.
192192
193193## Advanced Configuration
194194
195195### Detekt Version
196196
197- The default bundled version is ** 1.23.8 ** . To override it:
197+ The default bundled version is ** 2.0.0-alpha.2 ** . To override it:
198198
199199#### ` MODULE.bazel ` Configuration
200200
@@ -258,11 +258,11 @@ Each template may contain `{version}` which will be replaced with the version st
258258The detekt toolchain controls JVM flags, the JVM bytecode target version, and the Kotlin language
259259version compatibility. The defaults are:
260260
261- | Setting | Default |
262- | ------------------ | -------- |
261+ | Setting | Default |
262+ | ------------------ | -------------------- |
263263| ` jvm_flags ` | ` -Xms16m -Xmx128m ` |
264- | ` jvm_target ` | ` 1.8 ` |
265- | ` language_version ` | ` 2.0 ` |
264+ | ` jvm_target ` | ` 1.8 ` |
265+ | ` language_version ` | ` 2.3 ` |
266266
267267To override any of these, define a custom toolchain in a ` BUILD ` file:
268268
@@ -273,7 +273,7 @@ detekt_toolchain(
273273 name = " my_detekt_toolchain_impl" ,
274274 jvm_flags = [" -Xms16m" , " -Xmx512m" ],
275275 jvm_target = " 11" ,
276- language_version = " 1.9 " ,
276+ language_version = " 2.1 " ,
277277)
278278
279279toolchain(
@@ -302,13 +302,13 @@ register_toolchains("//mypackage:my_detekt_toolchain")
302302The ` plugins ` attribute accepts any Bazel label that provides ` JavaInfo ` . This covers both
303303published Maven artifacts and locally built JARs.
304304
305- ** Maven artifact** (e.g., the [ formatting rule set ] ( https://detekt.dev/docs/rules/formatting/ ) ):
305+ ** Maven artifact** (e.g., the [ ktlint wrapper plugin ] ( https://detekt.dev/docs/rules/formatting/ ) ):
306306
307307``` python
308308maven = use_extension(" @rules_jvm_external//:extensions.bzl" , " maven" )
309309maven.install(
310310 artifacts = [
311- " io.gitlab.arturbosch. detekt:detekt-formatting:1.23.8 " ,
311+ " dev. detekt:detekt-rules-ktlint-wrapper:2.0.0-alpha.2 " ,
312312 ],
313313)
314314use_repo(maven, " maven" )
@@ -320,7 +320,7 @@ load("@rules_detekt//detekt:defs.bzl", "detekt_test")
320320detekt_test(
321321 name = " my_detekt" ,
322322 srcs = glob([" src/main/kotlin/**/*.kt" ]),
323- plugins = [" @maven//:io_gitlab_arturbosch_detekt_detekt_formatting " ],
323+ plugins = [" @maven//:dev_detekt_detekt_rules_ktlint_wrapper " ],
324324)
325325```
326326
@@ -355,7 +355,7 @@ detekt_test(
355355)
356356```
357357
358- To extend Detekt's built-in defaults rather than replace them, also set ` build_upon_default_config = True ` :
358+ To extend Detekt's built-in configuration defaults rather than replace them, also set ` build_upon_default_config = True ` :
359359
360360``` python
361361detekt_test(
@@ -369,40 +369,45 @@ detekt_test(
369369
370370Type resolution enables more advanced static analysis by giving Detekt access to the full
371371compilation classpath — including return types, nullability, and symbol information. Rules
372- requiring it are annotated with ` @RequiresFullAnalysis ` in Detekt's source .
372+ requiring it extend the ` RequiresAnalysisApi ` interface .
373373
374- Type resolution is ** enabled by default** (` enable_type_resolution = True ` ). When enabled, the
375- appropriate bootclasspath (JDK or Android SDK) is always included. To also include your project's
376- library dependencies on the classpath, pass them via ` deps ` :
374+ Type resolution is controlled by the ` analysis_mode ` attribute:
375+
376+ - ` "full" ` — passes the compilation classpath to Detekt and enables type-aware rules. The
377+ appropriate bootclasspath (JDK or Android SDK) is always included. To also include your
378+ project's library dependencies, pass them via ` deps ` :
377379
378380``` python
379381load(" @rules_detekt//detekt:defs.bzl" , " detekt_test" )
380382
381383detekt_test(
382384 name = " my_detekt" ,
383385 srcs = glob([" src/main/kotlin/**/*.kt" ]),
386+ analysis_mode = " full" ,
384387 deps = [" :my_library" ], # provides the classpath for type resolution
385388)
386389```
387390
388- For ** Android targets ** , set ` is_android = True ` to include the Android SDK jar in the classpath :
391+ - ` "light" ` * (default) * — syntax-based analysis only; no classpath is passed to Detekt :
389392
390393``` python
391394detekt_test(
392395 name = " my_detekt" ,
393396 srcs = glob([" src/main/kotlin/**/*.kt" ]),
394- deps = [" :my_android_library" ],
395- is_android = True ,
397+ analysis_mode = " light" ,
396398)
397399```
398400
399- To opt out of type resolution entirely (syntax-only analysis), set ` enable_type_resolution = False ` :
401+ For ** Android targets** , set ` is_android = True ` to include the Android SDK jar in the classpath
402+ (requires ` analysis_mode = "full" ` ):
400403
401404``` python
402405detekt_test(
403406 name = " my_detekt" ,
404407 srcs = glob([" src/main/kotlin/**/*.kt" ]),
405- enable_type_resolution = False ,
408+ analysis_mode = " full" ,
409+ deps = [" :my_android_library" ],
410+ is_android = True ,
406411)
407412```
408413
@@ -411,14 +416,13 @@ detekt_test(
411416
412417### Reports
413418
414- By default, Detekt generates a text report internally (used for console output) . To export reports as build outputs,
415- enable them explicitly:
419+ Findings are always printed to the console via Detekt's built-in console reporter . To also export
420+ reports as build outputs, enable them explicitly:
416421
417422``` python
418423detekt_test(
419424 name = " my_detekt" ,
420425 srcs = glob([" src/main/kotlin/**/*.kt" ]),
421- txt_report = True , # {target_name}_detekt_report.txt
422426 html_report = True , # {target_name}_detekt_report.html
423427 xml_report = True , # {target_name}_detekt_report.xml (Checkstyle format, compatible with SonarQube)
424428 md_report = True , # {target_name}_detekt_report.md
0 commit comments