Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

bazel_rules_detekt

The Detekt (a Kotlin static analysis tool) integration for the Bazel build system.

Features

Usage

WORKSPACE Configuration

First of all you need to declare the rule in the WORKSPACE file. Please refer to GitHub releases for the version and the SHA-256 hashsum.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

rules_detekt_version = "see-github-releases-page"
rules_detekt_sha = "see-github-releases-page"

http_archive(
    name = "rules_detekt",
    sha256 = rules_detekt_sha,
    strip_prefix = "bazel_rules_detekt-{v}".format(v = rules_detekt_version),
    url = "https://github.com/buildfoundation/bazel_rules_detekt/archive/v{v}.tar.gz".format(v = rules_detekt_version),
)

load("@rules_detekt//detekt:dependencies.bzl", "rules_detekt_dependencies")
rules_detekt_dependencies()

load("@rules_detekt//detekt:toolchains.bzl", "rules_detekt_toolchains")
rules_detekt_toolchains()

BUILD Configuration

Once declared in the WORSKPACE file, the rule can be loaded in the BUILD file.

load("@rules_detekt//detekt:defs.bzl", "detekt")

detekt(
    name = "my_detekt",
    srcs = glob(["src/main/kotlin/**/*.kt"]),
)

See available attributes.

Execution

$ bazel build //mypackage:my_detekt

Results will be cached on successful runs.

Advanced Configuration

Detekt Version

Change the WORKSPACE file:

- rules_detekt_toolchains()
+ rules_detekt_toolchains(detekt_version = "x.y.z")

JVM Flags

Define a toolchain in a BUILD file:

load("@rules_detekt//detekt:toolchain.bzl", "detekt_toolchain")

detekt_toolchain(
    name = "my_detekt_toolchain_impl",
    jvm_flags = ["-Xms16m", "-Xmx128m"],
)

toolchain(
    name = "my_detekt_toolchain",
    toolchain = "my_detekt_toolchain_impl",
    toolchain_type = "@rules_detekt//detekt:toolchain_type",
)

Change the WORKSPACE file:

- rules_detekt_toolchains()
+ rules_detekt_toolchains(toolchain = "//mypackage:my_detekt_toolchain")