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

Gradle plugin is no longer compatible with Kotlin 2.0.0 and by Dependency Management Plugin #7384

Closed
vcruzmj opened this issue Jun 18, 2024 · 4 comments
Labels

Comments

@vcruzmj
Copy link

vcruzmj commented Jun 18, 2024

Expected Behavior

The current approach for mismatching versions of your project and the embedded one in detekt (in the context of Gradle runtime dependencies) is described here:
https://detekt.dev/docs/gettingstarted/gradle/#dependencies.

This was working in all versions except 2.0.0

configurations.all {
    resolutionStrategy.eachDependency {
        if (requested.group == "org.jetbrains.kotlin") {
            useVersion(io.gitlab.arturbosch.detekt.getSupportedKotlinVersion())
        }
    }
}

With this prior 2.0.0 you fix the message like when you build your project:

detekt was compiled with Kotlin 1.8.0 but is currently running with 1.7.0

Observed Behavior

With the same approach in kotlin 2.0.0 with the configuration, the :compileKotlin task now fails with this message:

Execution failed for task ':compileKotlin'.
> Could not resolve all files for configuration ':detachedConfiguration1'.
   > Failed to transform kotlin-reflect-1.9.23.jar to match attributes {artifactType=classpath-entry-snapshot, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for BuildToolsApiClasspathEntrySnapshotTransform: /home/anonym/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.9.23/ab01e1cc8428c2140891318838ad7039f6fa389a/kotlin-reflect-1.9.23.jar.
         > Artifact org.jetbrains.kotlin:kotlin-build-tools-impl must have version aligned with the version of KGP when compilation via the Build Tools API is disabled.

Steps to Reproduce

I create this repo with the main branch having the bug in kotlin 2.0.0 and the olderexample branch with this working in kotlin 1.9.4, both with detekt 1.23.6

Context

I'm trying to run detekt with Gradle in Kotlin 2.0.0 wit spring boot, but breaks the compilation of the project.
Can be related or duplicated from: #7304

Your Environment

  • Version of detekt used: 1.23.6
  • Version of Gradle used (if applicable): 8.8
  • Gradle scan link (add --scan option when running the gradle task):
  • Operating System and version: Ubuntu 22.04
  • Link to your project (if it's a public repository): https://github.com/vcruzmj/demo-detekt
@3flex
Copy link
Member

3flex commented Jun 18, 2024

We don't want or need the Kotlin version to be overridden on all configurations. We just need the detekt configuration to be left alone.

If you apply the config you've provided then you're overriding all configurations. That's having an impact on Kotlin itself which is what the warning is about.

There isn't much detekt can do about this directly. Your Gradle config needs to be fixed, or you need to stop the dependency plugin overriding the configs.

@vcruzmj
Copy link
Author

vcruzmj commented Jun 19, 2024

If you apply the config you've provided then you're overriding all configurations. That's having an impact on Kotlin itself which is what the warning is about.

But that is detekt official documentation https://detekt.dev/docs/gettingstarted/gradle/#dependencies, it's even in the logs of the warning.

There isn't much detekt can do about this directly. Your Gradle config needs to be fixed, or you need to stop the dependency plugin overriding the configs.

But below Kotlin 2.0.0 this was working, so, what is the official way to do it now? The only real change in my gradle configuration is kotlin from 1.9.4 to 2.0.0.
And stopping the dependency plugin to override the configs is like stopping using spring, that is not an option. There is a full discussion of this #6198 (still open).

But the main problem with this is that you used to have a workaround with kotlin versions lower than 2.0.0 described in your own configuration, which is not working anymore.

@vcruzmj
Copy link
Author

vcruzmj commented Jun 19, 2024

reading #6198 more in detail, I tried this:

configurations.matching { it.name == "detekt" }.all {
    resolutionStrategy.eachDependency {
        if (requested.group == "org.jetbrains.kotlin") {
            useVersion(io.gitlab.arturbosch.detekt.getSupportedKotlinVersion())
        }
    }
}

With that the project is fixed.

So instead of using configurations.all { I should use configurations.matching { it.name == "detekt" }.all {

I think (maybe it's just me) the documentation on https://detekt.dev/docs/gettingstarted/gradle/#dependencies should be updated to precise that configuration as an example, or I need to learn how to read better.

Thanks anyway for your help, and for this project.

@vcruzmj vcruzmj closed this as completed Jun 19, 2024
@BraisGabin
Copy link
Member

I think (maybe it's just me) the documentation on https://detekt.dev/docs/gettingstarted/gradle/#dependencies should be updated to precise that configuration as an example, or I need to learn how to read better.

Can you provide a PR fixing the documentation?

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

No branches or pull requests

3 participants