Ktlint: Cannot choose between the following variants of com.pinterest:ktlint:0.41.0:

Created on 19 Mar 2021  路  9Comments  路  Source: pinterest/ktlint

I have upgraded ktlint from 0.40.0 to 0.41.0. However, I am getting error when I execute ./gradlew ktlintCheck. How do I fix this? Thank you.

* What went wrong:
Execution failed for task ':loadKtlintReporters'.
> Could not resolve all files for configuration ':ktlint'.
   > Could not resolve com.pinterest:ktlint:0.41.0.
     Required by:
         project :
      > Cannot choose between the following variants of com.pinterest:ktlint:0.41.0:
          - runtimeElements
          - shadowRuntimeElements
        All of them match the consumer attributes:
          - Variant 'runtimeElements' capability com.pinterest:ktlint:0.41.0:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
                  - Provides org.gradle.jvm.version '8' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.localToProject 'public' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
          - Variant 'shadowRuntimeElements' capability com.pinterest:ktlint:0.41.0:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.dependency.bundling 'shadowed' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.status 'release' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it

Steps to Reproduce


  • Update to 0.41.0
  • Execute ./gradlew ktlintCheck

Your Environment

  • Version of ktlint used: 0.41.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlint-gradle plugin 10.0.0
  • Version of Gradle used (if applicable): 6.8.3

Most helpful comment

Since ktlint 0.41.0, shadowRuntimeElements variant is added, and you must select variant explicitly.

 dependencies {
     val ktlintVersion: String by project.ext.properties
    add("ktlint", "com.pinterest:ktlint:$ktlintVersion") {
        attributes {
            attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
        }
    }
}

All 9 comments

Please open a new issue in ktlint-gradle project. I think something wrong with your configuration.

Since ktlint 0.41.0, shadowRuntimeElements variant is added, and you must select variant explicitly.

 dependencies {
     val ktlintVersion: String by project.ext.properties
    add("ktlint", "com.pinterest:ktlint:$ktlintVersion") {
        attributes {
            attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
        }
    }
}

@ganadist thank you! How to achieve this with ktlint plugin?

If you are using ktlint with gradle plugin, it can run well without any modifications.

If you are using ktlint without gradle plugin, please follow https://github.com/pinterest/ktlint/pull/1120/files

@ganadist unfortunately, root project ktlintCheck fails with above error. Only ./gradlew :app:ktlintCheck works fine.

It seems that you are using allprojects notation.

And you might fix with using subprojects notation as example configuration.

I don't know the right solution for allprojects, but you might need to setup substituting a dependency with attributes

I think this was closed too early. I have my build.gradle to be configured exactly as README.md says in with Gradle section and I'm not using ktlint-gradle plugin, but still I've got the above error after upgrading to ktlint-0.41.0

@dimsuz This was closed because I moved this issue to ktlint plugin repo since this issue is mainly related to the plugin itself. And it is expected to be fixed in the next release.

But I don't use that plugin and still have this issue, that's what I've tried to say above.
Hence I think that either README should be updated to recommend only using that ktlint plugin or somehow updated to exclude this error in ktlint.

I use instructions from (without a plugin) section and they lead to the error.

Was this page helpful?
0 / 5 - 0 ratings