neerav
01/03/2024, 11:03 AMbuild.gradle.kts
file
But apart from app’s I have 3 other modules/sub library. So how to configure detekt so that it can also smell code from those modules/libraries as well ?
Thanks simple smile
detekt {
// Version of Detekt that will be used. When unspecified the latest detekt
// version found will be used. Override to stay on the same version.
toolVersion = "1.21.0"
// The directories where detekt looks for source files.
// Defaults to `files("src/main/java", "src/test/java", "src/main/kotlin", "src/test/kotlin")`.
source = files("src/main/java", "src/main/kotlin", "src/test/java")
// Builds the AST in parallel. Rules are always executed in parallel.
// Can lead to speedups in larger projects. `false` by default.
parallel = false
// Define the detekt configuration(s) you want to use.
// Defaults to the default detekt configuration.
config = files("$rootDir/config/detekt/detekt.yml")
// Applies the config files on top of detekt's default config file. `false` by default.
buildUponDefaultConfig = true
// Turns on all the rules. `false` by default.
allRules = true
// Specifying a baseline file. All findings stored in this file in subsequent runs of detekt.
baseline = file("$rootDir/config/detekt/baseline.xml")
// Disables all default detekt rulesets and will only run detekt with custom rules
// defined in plugins passed in with `detektPlugins` configuration. `false` by default.
disableDefaultRuleSets = false
// Adds debug output during task execution. `false` by default.
debug = true
// If set to `true` the build does not fail when the
// maxIssues count was reached. Defaults to `false`.
ignoreFailures = false
basePath = projectDir.absolutePath
reports.html.required.set(true)
reports.xml.required.set(true)
}
Brais Gabin
01/03/2024, 11:29 AMallprojects {/*confiugrration here*/}
or any other way you like to use to share configurartions between gradle modules.neerav
01/03/2024, 11:33 AMBrais Gabin
01/03/2024, 11:42 AMAtul Gupta
01/06/2024, 7:39 PMsettings.gradle[.kts]
) you have to create something like below
package com.acrobat.plugins.detekt
import io.gitlab.arturbosch.detekt.CONFIGURATION_DETEKT_PLUGINS
import io.gitlab.arturbosch.detekt.DetektPlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
class CustomDetektPlugin : Plugin<Project>
{
override fun apply(target: Project)
{
with(target) {
apply<DetektPlugin>() // Adding detekt plugin this should be added to your build.config as dependency
extensions.configure<DetektExtension> {
// If set to `true` the build does not fail when the
// maxIssues count was reached. Defaults to `false`.
ignoreFailures = false
// point to your custom config defining rules to run, overwriting default behavior
config.setFrom("$rootDir/config/detekt/detekt.yml") // this is common for each repo and is present inside your convention plugin
// a way of suppressing issues before introducing detekt
baseline = file("$projectDir/config/detekt/baseline.xml") // this will relative to your repos
// Specify the base path for file paths in the formatted reports.
// If not set, all file paths reported will be absolute file path.
basePath = projectDir.toString()
// Adds debug output during task execution. `false` by default.
debug = true
parallel = true
buildUponDefaultConfig = true
// Turn this on for auto correcting the code on Gradle build
// autoCorrect = true
}
// Uncomment below if you want to add ktlint detekt plugin(currently version is fetched from `libs.version.toml` which you need to create)
// dependencies.add(CONFIGURATION_DETEKT_PLUGINS, libs.findLibrary("detekt.ktlint").get())
}
}
}
internal inline val Project.libs
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")
Atul Gupta
01/06/2024, 7:41 PMlibs.version.toml
you can add below lines
[versions]
detektPlugin = "1.23.4"
[libraries]
detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detektPlugin" }
detekt-ktlint = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detektPlugin" }