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

brent

01/14/2020, 7:11 PM
I setup detekt a while back and am trying to update from
1.0.0-RC146
to
1.4.0
. Mostly working, but many of the rules simply aren't running. Looking through GH issues I see work was done around "type resolution" in v
1.1
. Is this working on multi-module Android projects yet? I see this comment from back in October with no corresponding PRs since: https://github.com/arturbosch/detekt/issues/2036#issuecomment-544105669
a

Artur Bosch

01/14/2020, 7:35 PM
Type resolution is used for the detekt tasks based on source sets e.g.
detektMain
or
detektTest
. This brings a huge performance penalty. Testing detekt as a kotlin compiler plugin (https://github.com/detekt/detekt-compiler-plugin) lead to huge benefits for us where rules relying on type resolution will come to shine.
b

brent

01/14/2020, 7:59 PM
Ok, so might not be related to Type Resolution then. I'm just running
gw detekt
on a module but some of the tasks seem to be silently not running. I might be experiencing this same issue: https://github.com/arturbosch/detekt/issues/2038#issuecomment-573917395
a

Artur Bosch

01/14/2020, 8:13 PM
Oh, I replied 11 minutes ago on that issue.
b

brent

01/14/2020, 8:34 PM
Ok, cool. Good timing 🙂
Only custom tasks are allowed to override the classpath property.
I saw a bunch of references to creating this type of custom task with
classpath
. Including this https://github.com/arturbosch/detekt/issues/1967#issuecomment-538165203 Do you have a working example handy? It's referenced as a possible solution in a few places, but I haven't seen a working example posted anywhere yet.
s

schalkms

01/14/2020, 8:54 PM
Please take a look at the following thread: https://github.com/arturbosch/detekt/issues/2038#issuecomment-573804409 There's an example project. You need to run
detektMain
in order to use rules that use type and symbol solving.
b

brent

01/14/2020, 8:59 PM
@schalkms but
detektMain
isn't available on Android projects.
s

schalkms

01/14/2020, 9:01 PM
Sorry, I read over the fact that you are on Android.
Android is still WIP as mentioned in the issue \2036.
b

brent

01/14/2020, 9:13 PM
Yup... so back to a custom task then? Looking for a working example if you know of one. 🙏
a

Artur Bosch

01/14/2020, 9:15 PM
Copy code
dependencies {
    detekt(project(":detekt-cli"))
    detektPlugins(project(":detekt-formatting"))
}

val detektAll by tasks.registering(Detekt::class) {
    description = "Runs over whole code base without the starting overhead for each module."
    parallel = true
    buildUponDefaultConfig = true
    include("**/*.kt")
    exclude("**/resources/**")
    exclude("**/build/**")
    exclude("**/*.kts")
    // baseline.set(file("$rootDir/config/detekt/baseline.xml"))
    classpath.setFrom(project.configurations.getByName("detekt"))
    reports {
        xml.enabled = false
        html.enabled = false
        txt.enabled = false
    }
}
I had to exclude kts files due to some strange errors:
Copy code
org.jetbrains.kotlin.util.KotlinFrontEndException: Front-end Internal error: Failed to analyze declaration Build_gradle
File being compiled at position: (1,42) in /build.gradle.kts
The root cause org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException was thrown at: org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler.diagnoseDescriptorNotFound(AbsentDescriptorHandler.kt:18)
b

brent

01/14/2020, 9:16 PM
Awesome. I think
classpath.setFrom(project.configurations.getByName("detekt"))
was the magic I was looking for. I'm out of time for today but I'll give this a shot tomorrow. Thanks!!
a

Artur Bosch

01/14/2020, 9:17 PM
No problem, make sure to include the
detektPlugins
classpath too if you want to use formatting or other plugins
👍 1
s

schalkms

01/15/2020, 6:34 PM
Cool, I didn't even know about that. @Artur Bosch We should persist this valuable information regarding type and symbol solving on the web site as well as https://github.com/arturbosch/detekt/issues/2038#issuecomment-574347664
👍 1
I'll open a new issue for that. @brent thanks for bringing this to our attention, asking the right questions and for helping us to improve missing parts in detekt's documentation.
b

brent

01/15/2020, 6:49 PM
👍. Thanks for all the help!!
Just a quick update on this... I was never able to get this working on my multi-module android project. Tried in kts and gradle version of scripts, both in buildSrc and at project level. In both cases the tasks run & pass but never seems to find any kotlin source to run on.
At this point I think I'm just going to stay on an old version of detekt and wait until Android-capable tasks are provided "out of the box".
2 Views