https://kotlinlang.org logo
#detekt
Title
# detekt
i

iamthevoid

12/05/2021, 8:19 AM
I use detekt 1.17.1 . It was added in project through root-gradle-script. I try to move it into precompiled script plugin and all looks correct, but behavior changed 0_o . Looks like my config not used, but used some default kind For example: When i leaved unused import before - i got
NoUnusedImports
issue and it autocorrects. Now i get another issue
UnusedImports
and these unused imports don't disappear (autocorrecting not working) Or before i got issue when blank lines were in end of file or between class members. Now i got
BUILD SUCCESSFUL
in same cases. I though it was wrong paths - but checked - config and baseline path points exactly where i want too. Sources folders also set correctly (when i comment they - i get
BUILD SUCCESSFUL
in cases when shouldn't) What do i miss? Config in thread
detekt-convention.gradle.kts
Copy code
import io.gitlab.arturbosch.detekt.Detekt

plugins { id("io.gitlab.arturbosch.detekt") }

dependencies { detektPlugins(detektPluginVersion()) }

detekt {
//    println(rootDir.absolutePath)
    toolVersion = detektVersion()
    config = rootProject.rootDirFiles("config/detekt/detekt.yml")
    baseline = rootProject.rootDirFile("config/detekt/baseline.xml")
    input.setFrom(
        "src/androidTest/java",
        "src/androidTest/kotlin",
        "src/debug/java",
        "src/debug/kotlin",
        "src/release/java",
        "src/release/kotlin",
        "src/main/kotlin",
        "src/main/java",
        "src/commonMain/kotlin",
        "src/androidMain/kotlin",
        "src/iosMain/kotlin"
    )
    parallel = true
    autoCorrect = true
    reports {
        xml {
            enabled = true
            destination = rootDirFile("build/report/detekt.xml")
        }
        txt {
            enabled = true
            destination = rootDirFile("build/report/detekt.txt")
        }
    }
}

tasks.withType<Detekt>().configureEach {
    jvmTarget = Versions.jvmTarget
}

repositories {
    mavenCentral()
}
Copy code
fun Project.rootDirFile(path: String): File {
    println(File("$rootDir/$path").run { "$absolutePath ${if (exists()) "exists" else "not exists"}" })
    return file("$rootDir/$path")
}

fun Project.rootDirFiles(path: String): ConfigurableFileCollection {
    println(File("$rootDir/$path").run { "$absolutePath ${if (exists()) "exists" else "not exists"}" })
    return files("$rootDir/$path")
}
Copy code
fun Project.detektPluginVersion(): String {
    return "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${detektVersion()}"
}

fun Project.detektVersion(): String {
    return version("versions.detekt")
}

// Try to get overrode version from project local.properties, or else fallback to project gradle
//  properties
private fun Project.version(key: String): String {
    return properties("${rootDir.absolutePath}/local.properties")?.getProperty(key)
        ?: project.properties[key]?.let(Any::toString).orEmpty()
}
rootProject/build.gradle.kts
Copy code
allprojects {
    .....
    apply(plugin = "detekt-convention")
    .....
}
b

Brais Gabin

12/05/2021, 11:49 AM
I think that the problem is the value that you are setting in
dependencies.detektPlugins
. It should `point to dete`kt-format and it points to the gradle plugin.
i

iamthevoid

12/05/2021, 1:11 PM
Wow, seriously) yep, i changed few lines. I'll check this today a bit later. Most likely you're right and it is the reason
Thanks! Your'e right
👍 1
9 Views