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

pedro

07/04/2020, 3:19 PM
I’m having problems using detekt in my project… (kotlin jvm project) I have different problems if I use 1.9.1 or 1.10.0 1.10.0
Copy code
Execution failed for task ':foo:detekt'.
> Could not resolve all files for configuration ':foo:detekt'.
   > Could not find io.gitlab.arturbosch.detekt:detekt-cli:1.10.0.
     Searched in the following locations:
       - <https://repo.maven.apache.org/maven2/io/gitlab/arturbosch/detekt/detekt-cli/1.10.0/detekt-cli-1.10.0.pom>
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
I have seen someone mentioning in github issues that it seems that some artifacts weren’t published in all repositories If I try to use 1.9.1:
Copy code
> Could not find org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.1.
     Searched in the following locations:
       - <https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-html-jvm/0.7.1/kotlinx-html-jvm-0.7.1.pom>
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :foo > io.gitlab.arturbosch.detekt:detekt-cli:1.9.1
I’ve tried all possible combinations of the instructions in the website and still haven’t got it to work. Can someone help?
This would be what my simple gradle file would look like. But I’ve tried many variations already.
Copy code
buildscript {
    dependencies {
//        classpath "org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.1"
        classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.9.1"
    }
}
plugins {
    id "io.gitlab.arturbosch.detekt" version "1.9.1"
}
It doesn’t help that the detekt recommends slightly different approaches in different places and some of them actually have syntax errors (happy to post some of those issues on a separate thread)
g

gammax

07/04/2020, 4:28 PM
Thanks for reporting. So the first issue you’re facing is related to this https://github.com/detekt/detekt/issues/2842 (1.10.0 is not yet on maven central, we’ll hopefully fix it soon).
👍 1
For your second point, can I ask you to try this configuration https://detekt.github.io/detekt/groovydsl.html#configuration-when-using-groovy-dsl ? Seems like you’re not specifying your
repositories{}
block and this is causing the build to fail.
It doesn’t help that the detekt recommends slightly different approaches in different places and some of them actually have syntax errors (happy to post some of those issues on a separate thread)
If you could actually create a Github Issue or open a PR, that would be great 👌
p

pedro

07/04/2020, 4:34 PM
I had tried with repositories before and it didn't work either (in the error message it reported as having looked at one repo only which is weird) I can try what you said when I get back to my computer and I'll update (not soon) Cheers
👍 1
b

Brais Gabin

07/04/2020, 6:18 PM
Kotlin html is only published in jcenter. So you need to add that repository at least for that dependency.
We discussed this before. It would be great to have that kotlin htlm in maven central but it's out of our control.
p

pedro

07/04/2020, 8:18 PM
I tried what “configuration on groovy dsl” link. As it is in the example, it fails with
only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
. Wrapping it with
buildscript { ... }
it goes back to the error message I posted, where it can’t find kotlinx html fwiw, this is the gradle file now:
Copy code
buildscript {
    repositories {
        jcenter()

        // or
        // also tried removing the repositories below this line
        mavenCentral()
        jcenter {
            content {
                // just allow to include kotlinx projects
                // detekt needs 'kotlinx-html' for the html report
                includeGroup "org.jetbrains.kotlinx"
            }
        }
    }
}

plugins {
    id "io.gitlab.arturbosch.detekt" version "1.9.1"
}
It shouldn’t affect this, but this is in a multi module project. Although to simplify things I am trying to apply this directly in one of the modules… This is an open source project so you can get exactly the same code as me if you want to try it on your computer
Also tried the instructions for android:
Copy code
buildscript {
    repositories {
        maven { url "<https://plugins.gradle.org/m2/>" }
        jcenter()
    }
    dependencies {
        classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.9.1"
    }
}

plugins {
    id "io.gitlab.arturbosch.detekt" version "1.9.1"
}
Same kotlinx html error
Feel free to suggest more tweaks, or show me a project that is able to use the version 1.9.1 of the plugin and I can try to find the differences…
g

gammax

07/04/2020, 8:23 PM
This is an open source project so you can get exactly the same code as me if you want to try it on your computer
Can you please link it?
p

pedro

07/04/2020, 8:34 PM
https://github.com/pedroql/mvflow I’m trying to do this in the mvflow-core module (the only module with actual kotlin code so far). So you can open
mvflow-core/build.gradle
file instead of the one in the root folder.
I’m working on the branch
feature/code_quality_improvements
but it shouldn’t affect this either.
g

gammax

07/04/2020, 8:42 PM
So this will work:
Copy code
plugins {
    id "io.gitlab.arturbosch.detekt" version "1.10.0"
}
repositories {
    mavenCentral()
    jcenter()
}
And if you want to use the
buildscript{}
syntax, also this will work:
Copy code
buildscript {
    repositories {
        maven { url "<https://plugins.gradle.org/m2/>" }
    }
    dependencies {
        classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.10.0"
    }

}
apply plugin: 'io.gitlab.arturbosch.detekt'

repositories {
    jcenter()
}
That being said, our documentation is misleading and we should update it. You are right.
p

pedro

07/04/2020, 8:50 PM
wow, that works! I was convinced that the dependencies for a plugin had to be declared inside the buildscript closure. So my problem was that I was missing the repositories in the top level! 😮
👍 1
thank you!!
I created this PR with some suggested changes. Left a few comments too to explain my reasoning but someone needs to decide what goes into the official docs. That’s just a suggestion! 🙂 https://github.com/detekt/detekt/pull/2845/
👍 1
94 Views