Hi all - I can’t get the detekt to run as a task f...
# detekt
p
Hi all - I can’t get the detekt to run as a task for specific module. I followed these steps for the app & submodules I want to apply it on: https://arturbosch.github.io/detekt/gradletask.html when I run
./gradlew :app:detekt
(or
./gradlew :submodule-name:detekt
) I get the following output:
Copy code
Task 'detekt' not found in project ':app'. Some candidates are: 'test'.
however if I run just
./gradlew detekt
it runs the task.
v
@Pamm Sar where did u apply the detekt plugin... inside app gradle file or outside root gradle file?
p
inside the root gradle file
v
ok
so i believe u have added detekt at root gradle file and applied the plugin as well in the same file and also defined detekt{} block in root gradle itself .. is it?
Copy code
./gradlew detekt
detekt will not be found inside ":app" sub tasks
p
oh okay I see
v
Copy code
apply plugin: "io.gitlab.arturbosch.detekt"

detekt {
    input = files("${rootProject.projectDir}/app/src/main/java")
    config = files("${rootProject.projectDir}/scripts/detekt/detekt.yml")
    baseline = file("${rootProject.projectDir}/scripts/detekt/detekt-baseline.xml")
    reports {
        xml {
            enabled = true
            destination = file("${rootProject.projectDir}/app/build/reports/detekt/detekt-results.xml")
        }
    }
}
p
so i just added the following in the root gradle and havent added any plugins or dependencies in the app gradle
Copy code
configurations {
    detekt
}

task detekt(type: JavaExec) {
    main = "io.gitlab.arturbosch.detekt.cli.Main"
    classpath = configurations.detekt
    def input = "$projectDir/app/src/main/java"
    def config = "$projectDir/Scripts/detekt-config.yml"
    def params = [ '-i', input, '-c', config]
    args(params)
}

dependencies {
    detekt 'io.gitlab.arturbosch.detekt:detekt-cli:1.8.0'
}
Do I have to following these steps as well in order to use detekt task in the specific modules? https://arturbosch.github.io/detekt/groovydsl.html
v
ok.. i never tried that
but i used like this
Copy code
detekt {
    input = files("${rootProject.projectDir}/app/src/main/java", "\"${rootProject.projectDir}/commonLib/src/main/java\"")
}
p
sorry it was more of a question haha if this should be applied as well
v
got it..
p
but yes currently I only have it like you suggested and it work okay but I wanted to change it to a task instead and got a bit stuck as it keeps failing for some reason
v
i see that your custom task extends from JavaExec
did u try changing that to
Copy code
Detekt
p
I haven’t tried this tbh as I just followed what was in this doc but I will give it a go now
Copy code
> Could not set unknown property 'main' for task ':detekt' of type io.gitlab.arturbosch.detekt.Detekt.
I managed to resolve this and using a custom detekt task inside the app/build.gradle file: https://detekt.github.io/detekt/groovydsl.html#defining-custom-detekt-task
a
I'm not sure if you only apply the detekt plugin to the root build file. If you have many submodules you have to apply the plugin for all sub projects:
Copy code
subprojects {
    apply {
        plugin("detekt...")
    }
}
👍 1