When running `app:build` task the `detekt` task ru...
# detekt
i
When running
app:build
task the
detekt
task runs as well. How can I disable this behaviour?
or run
Copy code
./gradlew -x detekt app:build
j
build
runs
check
which runs
detekt
. It is usual that build runs almost everything, what are you trying to do? maybe you want to compile + test, so
./gradlew assemble test
would be enough
m
i
At first glance it looks like running tests and linters with Gradle
check
(defined as
check
task dependency) task is great idea. However this has one major downside - when PR checks build fail you can't instantly determine the reason of the failure - you have to you have to manually read through (usually very long) log file. The solution for this is to runn all check in parallel (see screenshot). Other linters such as
spotless
are solving this issue by introducing configuration parameter:
Copy code
spotless {
    isEnforceCheck = false
}
Instead of heaving dedicated parameter Detekt proposes disabling this check by filtering tasks:
Copy code
tasks.named("check").configure {
    this.setDependsOn(this.dependsOn.filterNot {
        it is TaskProvider<*> && it.name == "detekt"
    })
}
I am using Gradle conventions plugins to setup detekt and for me the above solution does not work
e
1. you can use
--continue
so that Gradle runs as many tasks as it can even if some fail (only dependent tasks will be cancelled). the final build will still fail if there were any failures. 2. detekt emits reports so you can just grab those. and/or enable SARIF output, it shows up directly in the GitHub UI, https://detekt.dev/docs/introduction/reporting/#integration-with-github-code-scanning
i
Continue does not solve the problem (detekt has
ignoreFailures
option). The main issue here is lack of visibility - you have to dig deep to understand which check has failed and why (detekt in not the only verification task, so there is very long build log and bunch of reports).
j
Why running build filtering tasks instead of running each of those task individually?
i
I run different tasks to verify different aspects of the project separately: • build - does the project builds • detekt - check detekt • tests - run tests
j
I had a similar setup and I was running in parallel each individual check + assemble
I think you want assemble instead of build
i
BTW I am currently can run detekt with
build
but this is redundant as build task fails because of detekt issue - I would like to have more separation
j
I had this setup: • assemble (compile sources) • test • detekt • spotless • qodana
e
in Gradle (inherited from Maven terminology), "build" intentionally includes tests. "assemble" is "build but not test".
j
yeah, the name build is misleading
e
but I think
--continue
helps reduce duplicated work. instead of having multiple jobs that all build the same code, just have one job that does as much as possible. Gradle can still work in parallel (although you need to enable configuration cache to get the full benefits)
j
still running in parallel can help to finish the checks earlier
but it cost more money 💰
i
I agree this is always a tradeoff. I have private dedicated server, so this extra visibility benefit adds minimal cost for me. BTW @Javier comment about misleading name is actually very good one, I will investigate this
j
build basically runs almost everything as it is assemble + check, so it compiles the code, run the tests, run all verification tasks (spotless, detekt, etc). There are some exceptions, for example Android integration tests don’t run with build and must be run manually.
i
FYI Detekt is considering to add a new config option
Copy code
detekt {
    isEnforceCheck = false
}
https://github.com/detekt/detekt/issues/5965#issuecomment-1497392847