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

iliask

12/16/2021, 2:23 PM
Hello everyone, I was wondering: Is it possible to make
detekt
(without type resolution at the moment) always run after
assemble
tasks automatically, either through a detekt configuration or some gradle magic?
g

gammax

12/16/2021, 2:24 PM
assemble.dependsOn(detektMain)
should do the job for you 👍
i

iliask

12/16/2021, 2:34 PM
Thanks for the quick answer! I am working on a multi-module android project and I added a custom
detektAll
task in the root
build.gradle
Copy code
tasks.register("detektAll", Detekt) {
...
}
When adding
assemble.dependsOn(detektAll)
in the root
build.gradle
then gradle sync fails 🤔
Copy code
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'assemble' for root project
g

gammax

12/16/2021, 2:35 PM
Could not get unknown property ‘assemble’ for root project
This happens because you don’t have an
assemble
task (yet)
i

iliask

12/16/2021, 2:38 PM
When running
./gradlew tasks
the
assemble
task is present. When I add the suggested snippet in the app module
build.gradle
then gradle syncs successfully. Perhaps the assemble tasks are not "seen" by the root
build.gradle
?
g

gammax

12/16/2021, 2:41 PM
Perhaps the assemble tasks are not “seen” by the root 
build.gradle
 ?
Sort of. The
assemble
task are “local” to your subprojects. While I suppose your
detektAll
task is declared in the top level build.gradle
i

iliask

12/16/2021, 2:46 PM
Ok I see it's more of a gradle than a detekt topic. Thanks for your help! Out of curiosity btw are there any plans to "streamline" multi-module support more officially?
g

gammax

12/16/2021, 2:47 PM
You like having a
detetkAll
task provided by default?
i

iliask

12/16/2021, 2:49 PM
Personally I think it would be useful since a lot of android projects are/move towards the multi-module approach. With my "beginner-level" gradle knowledge I needed to connect together some article sources to make it work 😁
g

gammax

12/16/2021, 3:09 PM
The reality is detekt already supports multimodule out of the box. The fact that you want to have a top level
detektAll
goes against the Gradle philosophy
i

iliask

12/16/2021, 3:18 PM
I see perhaps I took the wrong approach with
detektAll
. Would you recommend instead to add detekt dependency in every module via
allprojects {}
or something else?
g

gammax

12/16/2021, 3:21 PM
If you invoke
./gradlew detektMain
you’re essentially saying to Gradle to invoke
detetkMain
on all the subprojects. That should be sufficient to run detekt on all the subprojects (i.e. you don’t need a
detetkAll
). You can specify the dependency between assemble and detektAll a the project level then.
i

iliask

12/16/2021, 3:28 PM
Ok I will integrate detekt with this approach. Thank you for the help, appreciate it! 🙌
e

ephemient

12/16/2021, 6:22 PM
note:
detekt
is already added as a dependency to the standard
check
task, which means if you run either
gradle check
or
gradle build
, it will also run
detekt
g

gammax

12/16/2021, 8:22 PM
☝️ Yup that’s true, but that’s not the case for Type Resolution tasks