In a multi module Android project with product fla...
# detekt
e
In a multi module Android project with product flavors (let's say we have a flavor
paid
) I need to run two different Detekt tasks to get full coverage: 1.
./gradlew detektPaidDebug
only finds defects in the app module but not in library modules 2.
./gradlew detektDebug
only finds defects in library modules but not in the app module When I run
./gradlew detekt
it finds defects in all modules. However we want to run with type resolution. Is this a known issue or am I doing something wrong? As a reference, the configuration
Copy code
subprojects {
    apply plugin: "io.gitlab.arturbosch.detekt"
    // includes the custom rules module
    dependencies {
        detektPlugins(project(":lib-code-quality"))
    }
    def baseDir = rootProject.projectDir
    def baseLineFile = file("$baseDir/config/detekt/${project.name}/detekt-baseline.xml")
    def reportPath = "$baseDir/build/reports/detekt/${project.name}"
    detekt {
        debug = false
        parallel = true
        config.setFrom(file("$baseDir/config/detekt/detekt-config.yml"))
        baseline = baseLineFile
        buildUponDefaultConfig = true
        allRules = true
    }
    tasks.withType(Detekt).configureEach {
        reports {
            html.required.set(true)
            html.outputLocation.set(file("$reportPath/detekt.html"))
            txt.required.set(true)
            txt.outputLocation.set(file("$reportPath/detekt.txt"))
            xml.required.set(false)
            md.required.set(false)
            sarif.required.set(false)
        }
    }
    tasks.withType(DetektCreateBaselineTask).configureEach {
        baseline.set(baseLineFile)
    }
}
b
./gradlew detektMain detektTest
e
detektMain
runs all combinations (~15) of build types and flavors we have, I don't want to run it on most of them
b
Oh! I understand the question now. I had exactly the same issue. What I did was to create in all my projects a task called
detektAll
.
Copy code
fun Project.setupDetekt(vararg buildVariants: String) {
    val detektAll = tasks.register("detektAll") {
        group = "verification"
        description = "Run detekt analysis in all the modules."

        dependsOn(
            if (buildVariants.isEmpty()) {
                listOf(
                    project.tasks.named("detektMain"),
                    project.tasks.named("detektTest"),
                )
            } else {
                buildVariants.flatMap { variant ->
                    listOf(
                        project.tasks.named("detekt$variant"),
                        project.tasks.named("detekt${variant}UnitTest"),
                    )
                }
            },
        )
    }
In
app
I call
setupDetekt
. With the variant that I want and in the others I just use the
detektMain
(all my modules have
debug
build variant disable by default to avoid that repetition, not only with detekt but also with
test
and others).
283 Views