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

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

Closed
nuhkoca opened this issue Mar 20, 2021 · 10 comments · Fixed by #459
Closed

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

nuhkoca opened this issue Mar 20, 2021 · 10 comments · Fixed by #459
Labels

Comments

@nuhkoca
Copy link
Contributor

nuhkoca commented Mar 20, 2021

I have upgraded ktlint from 0.40.0 to 0.41.0. However, I am getting below error when I run ./gradlew ktlintCheck. There is no change in my config between two versions. 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

Sorry, since it is a private repo, I am posting the relative parts here.

ktlint configuration

ktlint {
   android = true
   enableExperimentalRules = true
   ignoreFailures = false
   version = "0.41.0"
   filter {
       exclude("**/generated/**", "**/build/**")
   }
   reporters {
       reporter "html"
   }
}

.editorconfig

# EditorConfig: http://editorconfig.org
root=true

[*]
insert_final_newline=true
disabled_rules=import-ordering,chain-wrapping,experimental:spacing-between-declarations-with-comments

[*.{kt,kts}]
max_line_length=120

[**/test/**.kt]
max_line_length=off

Working env

  • ktlint version: 0.41.0
  • ktlint-gradle plugin version: 10.0.0
  • Gradle: 6.8.3
  • Android Studio: 4.1.3
@Tapchicoma
Copy link
Collaborator

Wild guess - do you have mavenCentral() repo in repositories { .. } block?

For me using KtLInt 0.41.0 works ok with this plugin, so would be nice to provide some repo reproducing this issue.

@nuhkoca
Copy link
Contributor Author

nuhkoca commented Mar 21, 2021

@Tapchicoma yes we do have mavenCentral(). I think I have found the problem. As far as I se, it is originating from explicit definition of ktlint version inside ktlint block. For instance;

This works;

ktlint {
  android = true
}

This doesn't work;

ktlint {
  android = true
  version = "0.41.0"
}

Created a sample repo for you: https://github.com/nuhkoca/ktlint-sample

@Tapchicoma
Copy link
Collaborator

I see that running ./gradlew :app:ktlintCheck task completes with KtLint errors. It is only the root project ktlintCheck fails 🤔

@Tapchicoma
Copy link
Collaborator

Tapchicoma commented Mar 21, 2021

Doing this diff solves the issue:

diff --git a/build.gradle b/build.gradle
index 6c0ece4..28f291d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,7 +7,7 @@ buildscript {
     }
     dependencies {
         classpath "com.android.tools.build:gradle:4.1.3"
-        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+        //classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
@@ -16,6 +16,7 @@ buildscript {
 
 plugins {
     id "org.jlleitschuh.gradle.ktlint" version "10.0.0"
+    id "org.jetbrains.kotlin.jvm" version "1.4.31"
 }
 
 allprojects {
@@ -42,6 +43,6 @@ allprojects {
     }
 }
 
-task clean(type: Delete) {
-    delete rootProject.buildDir
-}
\ No newline at end of file
+//task clean(type: Delete) {
+//    delete rootProject.buildDir
+//}

Generally it is not advised to use mix of old classpath approach and new plugin api - check second question in faq.

Though changing in sample project ktlint-gradle plugin to use old classpath approach does not fix the initial issue, so this is the bug.

@nuhkoca
Copy link
Contributor Author

nuhkoca commented Mar 21, 2021

@Tapchicoma yes, using the new plugin api fixes this issue. However, I am not sure I can do these changes in the private repo immediately. As of now, all plugins are placed into the buildscript. Please let me know when you have a fix for this. Thank you!

@nuhkoca
Copy link
Contributor Author

nuhkoca commented Mar 24, 2021

@Tapchicoma seems, we have an answer here

What do you think of it? Could it be feasible in the plugin in the near future?

@Tapchicoma
Copy link
Collaborator

@nuhkoca to workaround the issue you could temporary add following code into build.gradle:

configurations.named("ktlint").configure {
    resolutionStrategy {
        dependencySubstitution {
            substitute module("com.pinterest:ktlint") with variant(module("com.pinterest:ktlint:0.41.0")) {
                attributes {
                    attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
                }
            }
        }
    }
}

@nuhkoca
Copy link
Contributor Author

nuhkoca commented Apr 6, 2021

Thank you @Tapchicoma I'll do it as a workaround for now. So will you fix this this in the next release?

@Tapchicoma
Copy link
Collaborator

Will be included into #459 PR.

@BraisGabin
Copy link

If someone want the workaroud using Kotlin DSL:

configurations.named("ktlint").configure {
    resolutionStrategy {
        dependencySubstitution {
            substitute(module("com.pinterest:ktlint")).with(variant(module("com.pinterest:ktlint:0.41.0")) {
                attributes {
                    attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling::class, Bundling.EXTERNAL))
                }
            })
        }
    }
}

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.

3 participants