Hi, I’m trying to configure Android project that uses Detekt and also has custom rules. For that rea...
b
Hi, I’m trying to configure Android project that uses Detekt and also has custom rules. For that reason application uses
detektDebug
But recently I’m trying to validate “.kts” files too. But when I configure
DetektExtension
with that paths(for root
settings.gradle.kts
files too),
detektDebug
task does not validates that files. It only validates default paths. On CI environment application is validated only with
detektDebug
task because of baseline files. Is there any way to configure
detektDebug
task inputs via Extensions? When I tried to reach the task via
tasks.named<Detekt>("detektDebug")
call it was tricky, I had to do this call on
doAfter
block. Also project uses published plugins to apply all required plugins, so ı didn’t want to add confusing tricks on there. Also I tried to configure
detektDebug
task to depend on
detekt
task and configured
DetektExtension
to only check “.kts” files but when I do that
--continue
option become useless. (CI environment uses
--continue
option and we would like to provide complete reports to developers so that they can fix all issues at once instead of waiting results for each validation errors commit by commit.)
BTW I was able to reproduce this on a new project: • Create new empty project on Android Studio • Apply Detekt plugin to both root and app level
build.gradle
scripts. • Create new “.kt” file under
app/src/main/java
and put some validation errors. • Add this extension configuration to
:app
’s
build.gradle
to clear
detekt
’s validation check paths:
Copy code
detekt {
    source.from.clear()
}
After this when I run
./gradlew detekt
it passes because it does not check any files. But when I run
./gradlew detektDebug
it still checks default paths and finds violations.
e
detektDebug
is configured for type resolution (https://detekt.dev/docs/gettingstarted/type-resolution/#enabling-on-an-android-project) - it only works if it's using the same sources and dependencies as the compiler
if you want to run Detect on the build scripts, I would recommend creating a new task for them, e.g.
Copy code
import io.gitlab.arturbosch.detekt.Detekt
import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP

tasks.register<Detekt>("detektScripts") { 
    group = VERIFICATION_GROUP
    description = "Run detekt analysis for Kotlin scripts"
    source(files().apply { from(layout.projectDirectory.asFileTree.matching { include("*.kts") }) })
}
set up CI to run both tasks
or create a new task (or reuse an existing lifecycle task like
check
) that depends on everything you want to run on CI - all its dependencies should try execute when you use
--continue
, even if it can't due to some failed dependencies, but that doesn't matter because it doesn't do anything on its own anyway
b
Thank you for your quick response. I’ll discuss this with my teammates. Also its ok if we configure
detekt
task to check only
.kts
files right? Because we want to lover task count on the project to lower IDE Sync durations.
e
you could do that but I would find that confusing. I somewhat doubt registering a task makes a noticeable difference in sync times, in my experience the number of modules and configurations is what can add to it
b
You’re right but in the project we have 700+ modules and we use several plugins that adds so many tasks, we’re trying to reduce that number. 😅 Also I didn’t wrote in the first message but aim for doing this is to get rid of Ktlint from the project but we don’t want to lose validations on
.gradle.kts
files. Thats why I was trying to add this validations to Detekt.
179 Views