Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detekt 1.22.0 no longer works with kotlin <1.7 #5551

Closed
Hexcles opened this issue Nov 21, 2022 · 8 comments · Fixed by #5726
Closed

detekt 1.22.0 no longer works with kotlin <1.7 #5551

Hexcles opened this issue Nov 21, 2022 · 8 comments · Fixed by #5726
Labels

Comments

@Hexcles
Copy link
Contributor

Hexcles commented Nov 21, 2022

Expected Behavior

detekt 1.22.0 continues to work with projects using kotlin 1.6.21, as the doc doesn't mention kotlin 1.7 as a requirement.

Observed Behavior

Caused by: java.lang.reflect.InvocationTargetException
        at jdk.internal.reflect.GeneratedMethodAccessor2658.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at io.gitlab.arturbosch.detekt.invoke.DefaultCliInvoker.invokeCli(DetektInvoker.kt:58)
        ... 125 more
Caused by: java.lang.NoSuchMethodError: 'void org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt.configureJdkClasspathRoots(org.jetbrains.kotlin.config.CompilerConfiguration)'
        at io.github.detekt.parser.KotlinEnvironmentUtilsKt.createCompilerConfiguration(KotlinEnvironmentUtils.kt:122)
        at io.gitlab.arturbosch.detekt.core.settings.EnvironmentFacade$environment$2.invoke(EnvironmentAware.kt:36)
        at io.gitlab.arturbosch.detekt.core.settings.EnvironmentFacade$environment$2.invoke(EnvironmentAware.kt:35)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at io.gitlab.arturbosch.detekt.core.settings.EnvironmentFacade.getEnvironment(EnvironmentAware.kt:35)
        at io.gitlab.arturbosch.detekt.core.ProcessingSettings.getEnvironment(ProcessingSettings.kt)
        at io.gitlab.arturbosch.detekt.core.KtTreeCompiler.<init>(KtTreeCompiler.kt:14)
        at io.gitlab.arturbosch.detekt.core.tooling.ParsingStrategyKt$inputPathsToKtFiles$1.invoke(ParsingStrategy.kt:24)
        at io.gitlab.arturbosch.detekt.core.tooling.ParsingStrategyKt$inputPathsToKtFiles$1.invoke(ParsingStrategy.kt:23)
        at io.gitlab.arturbosch.detekt.core.tooling.Lifecycle$analyze$filesToAnalyze$1.invoke(Lifecycle.kt:38)
        at io.gitlab.arturbosch.detekt.core.tooling.Lifecycle$analyze$filesToAnalyze$1.invoke(Lifecycle.kt:38)
        at io.gitlab.arturbosch.detekt.core.util.PerformanceMonitor.measure(PerformanceMonitor.kt:42)
        at io.gitlab.arturbosch.detekt.core.tooling.Lifecycle$DefaultImpls.measure(Lifecycle.kt:34)
        at io.gitlab.arturbosch.detekt.core.tooling.Lifecycle$DefaultImpls.analyze(Lifecycle.kt:38)
        at io.gitlab.arturbosch.detekt.core.tooling.DefaultLifecycle.analyze(Lifecycle.kt:61)
        at io.gitlab.arturbosch.detekt.core.tooling.AnalysisFacade$runAnalysis$1.invoke(AnalysisFacade.kt:48)
        at io.gitlab.arturbosch.detekt.core.tooling.AnalysisFacade$runAnalysis$1.invoke(AnalysisFacade.kt:47)
        at io.gitlab.arturbosch.detekt.core.tooling.ProcessingSpecSettingsBridgeKt.withSettings(ProcessingSpecSettingsBridge.kt:26)
        at io.gitlab.arturbosch.detekt.core.tooling.AnalysisFacade.runAnalysis$detekt_core(AnalysisFacade.kt:47)
        at io.gitlab.arturbosch.detekt.core.tooling.AnalysisFacade.run(AnalysisFacade.kt:25)
        at io.gitlab.arturbosch.detekt.cli.runners.Runner.call(Runner.kt:33)
        at io.gitlab.arturbosch.detekt.cli.runners.Runner.execute(Runner.kt:23)
        ... 128 more

Steps to Reproduce

Context

detekt calls https://cs.github.com/JetBrains/kotlin/blob/b6481ed891a35d5f148209a9666462b5248046e3/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JvmContentRoots.kt#L91 which does not seem to exist in kotlin 1.6: https://github.com/JetBrains/kotlin/blob/1.6.20/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JvmContentRoots.kt

Your Environment

  • Version of detekt used: 1.22.0
  • Version of Gradle used (if applicable): 7.4.2
  • Version of kotlin compiler: 1.6.21
@Hexcles Hexcles added the bug label Nov 21, 2022
@3flex
Copy link
Member

3flex commented Nov 21, 2022

Without a build scan link I can't confirm, but I suspect the Kotlin version that detekt uses (which can be different to the project's Kotlin version) is being inadvertently overridden. Please see #5021 (comment) and the following comments and see if this helps you.

@tanadeau
Copy link

I encountered the same issue. I added the dependency override mentioned in #5021 and still see the same issue. The scan is:

org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.21 (selected by rule)
  Variant runtime:
    | Attribute Name             | Provided     | Requested |
    |----------------------------|--------------|-----------|
    | org.gradle.category        | library      |           |
    | org.gradle.libraryelements | jar          |           |
    | org.gradle.status          | release      |           |
    | org.gradle.usage           | java-runtime |           |

org.jetbrains.kotlin:kotlin-compiler-embeddable:1.7.21 -> 1.6.21
\--- io.gitlab.arturbosch.detekt:detekt-api:1.22.0
     +--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0
     |    \--- io.gitlab.arturbosch.detekt:detekt-cli:1.22.0
     |         \--- detekt
     +--- io.gitlab.arturbosch.detekt:detekt-tooling:1.22.0
     |    +--- io.gitlab.arturbosch.detekt:detekt-cli:1.22.0 (*)
     |    +--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0 (*)
     |    \--- io.gitlab.arturbosch.detekt:detekt-rules-errorprone:1.22.0
     |         \--- io.gitlab.arturbosch.detekt:detekt-rules:1.22.0
     |              \--- io.gitlab.arturbosch.detekt:detekt-cli:1.22.0 (*)
     +--- io.gitlab.arturbosch.detekt:detekt-report-md:1.22.0
     |    \--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0 (*)
     \--- io.gitlab.arturbosch.detekt:detekt-metrics:1.22.0
          +--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0 (*)
          \--- io.gitlab.arturbosch.detekt:detekt-report-md:1.22.0 (*)

org.jetbrains.kotlin:kotlin-compiler-embeddable:{strictly 1.7.21} -> 1.6.21
\--- io.gitlab.arturbosch.detekt:detekt-cli:1.22.0
     \--- detekt

org.jetbrains.kotlin:kotlin-compiler-embeddable:1.7.21 -> 1.6.21
+--- io.gitlab.arturbosch.detekt:detekt-parser:1.22.0
|    +--- io.gitlab.arturbosch.detekt:detekt-cli:1.22.0
|    |    \--- detekt
|    \--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0
|         \--- io.gitlab.arturbosch.detekt:detekt-cli:1.22.0 (*)
\--- io.gitlab.arturbosch.detekt:detekt-psi-utils:1.22.0
     +--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0 (*)
     +--- io.gitlab.arturbosch.detekt:detekt-parser:1.22.0 (*)
     \--- io.gitlab.arturbosch.detekt:detekt-api:1.22.0
          +--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0 (*)
          +--- io.gitlab.arturbosch.detekt:detekt-tooling:1.22.0
          |    +--- io.gitlab.arturbosch.detekt:detekt-cli:1.22.0 (*)
          |    +--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0 (*)
          |    \--- io.gitlab.arturbosch.detekt:detekt-rules-errorprone:1.22.0
          |         \--- io.gitlab.arturbosch.detekt:detekt-rules:1.22.0
          |              \--- io.gitlab.arturbosch.detekt:detekt-cli:1.22.0 (*)
          +--- io.gitlab.arturbosch.detekt:detekt-report-md:1.22.0
          |    \--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0 (*)
          \--- io.gitlab.arturbosch.detekt:detekt-metrics:1.22.0
               +--- io.gitlab.arturbosch.detekt:detekt-core:1.22.0 (*)
               \--- io.gitlab.arturbosch.detekt:detekt-report-md:1.22.0 (*)

(*) - dependencies omitted (listed previously)

@3flex
Copy link
Member

3flex commented Nov 22, 2022

@tanadeau that shows exactly what I'm describing. The Kotlin version expected by detekt is being overridden by something in your Gradle config.

detekt has its own Gradle configuration for its dependencies which will work when they're not overridden.

@TWiStErRob
Copy link
Member

TWiStErRob commented Nov 30, 2022

as the doc doesn't mention kotlin 1.7 as a requirement.

Does this count? https://detekt.dev/docs/next/introduction/compatibility#tool-versions

Maybe it could be improved to be more explicit?

@Hexcles
Copy link
Contributor Author

Hexcles commented Jan 5, 2023

@TWiStErRob oh thanks for the pointer! I didn't know about it.

I think this deserves a callout in the chart and/or changelog, something like "detekt 1.22 requires kotlin 1.7", as all the existing wording is optional.

@TWiStErRob
Copy link
Member

@cortinico can we change the changelog? I agree that the table is not expressive, because some of those are hard requirements, some are just "we tested with" compatibility suggestions.

@3flex
Copy link
Member

3flex commented Jan 5, 2023

Just remember that while detekt needs to use a specific version of Kotlin, that doesn't mean the project it's applied to has to use that same version.

It's perfectly fine for a project to use Kotlin 1.8.0 while detekt is using Kotlin 1.7.21 for example. Things only break when detekt's configuration is overridden.

So if the changelog or readme is updated it should try to make that clear. Maybe what we can do is put a note at the top of the changelog for each release saying that detekt uses Kotlin x.y.z and that version shouldn't be overridden, with a link to docs explaining how that issue can be spotted and what to do about it.

@Hexcles
Copy link
Contributor Author

Hexcles commented Jan 6, 2023

Yeah, something like "Note: if you override kotlin version for detekt, this version of detekt no longer works with kotlin 1.6.*."

BTW, I just tested that kotlin 1.7.10 would also work. And based on the kotlin change history, I'm guessing 1.7.0 should be fine, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants