nebula-plugins / gradle-lint-plugin

A pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts.
Apache License 2.0
769 stars 88 forks source link

No matching variant was found #336

Closed yairogen closed 3 years ago

yairogen commented 3 years ago

I am getting the following errors on all my dependencies when running: gradlew lintGradle.

I tried to add the workaround mentioned in: https://github.com/gradle/gradle/issues/6854 like this and it didn't help:

configurations.all {
    if (name.startsWith("incrementalScalaAnalysis")) {
        extendsFrom = []
    }
}

Note: The following is a sample. I get this for all my dependencies.


     Required by:
         project :
      > No matching variant of org.scala-lang:scala-library:2.12.10 was found. The consumer was configured to find a usage of 'incremental-analysis' of a component but:
          - Variant 'compile' capability org.scala-lang:scala-library:2.12.10:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'enforced-platform-compile' capability org.scala-lang:scala-library-derived-enforced-platform:2.12.10:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'enforced-platform-runtime' capability org.scala-lang:scala-library-derived-enforced-platform:2.12.10:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'platform-compile' capability org.scala-lang:scala-library-derived-platform:2.12.10:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'platform-runtime' capability org.scala-lang:scala-library-derived-platform:2.12.10:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'runtime' capability org.scala-lang:scala-library:2.12.10:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component
   > Could not resolve com.typesafe.scala-logging:scala-logging_2.12:3.9.2.
     Required by:
         project :
      > No matching variant of com.typesafe.scala-logging:scala-logging_2.12:3.9.2 was found. The consumer was configured to find a usage of 'incremental-analysis' of a component but:
          - Variant 'compile' capability com.typesafe.scala-logging:scala-logging_2.12:3.9.2:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'enforced-platform-compile' capability com.typesafe.scala-logging:scala-logging_2.12-derived-enforced-platform:3.9.2:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'enforced-platform-runtime' capability com.typesafe.scala-logging:scala-logging_2.12-derived-enforced-platform:3.9.2:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'platform-compile' capability com.typesafe.scala-logging:scala-logging_2.12-derived-platform:3.9.2:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'platform-runtime' capability com.typesafe.scala-logging:scala-logging_2.12-derived-platform:3.9.2:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'runtime' capability com.typesafe.scala-logging:scala-logging_2.12:3.9.2:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component
   > Could not resolve org.scalactic:scalactic_2.12:3.1.0.
     Required by:
         project :
      > No matching variant of org.scalactic:scalactic_2.12:3.1.0 was found. The consumer was configured to find a usage of 'incremental-analysis' of a component but:
          - Variant 'compile' capability org.scalactic:scalactic_2.12:3.1.0:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'enforced-platform-compile' capability org.scalactic:scalactic_2.12-derived-enforced-platform:3.1.0:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'enforced-platform-runtime' capability org.scalactic:scalactic_2.12-derived-enforced-platform:3.1.0:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'platform-compile' capability org.scalactic:scalactic_2.12-derived-platform:3.1.0:
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'platform-runtime' capability org.scalactic:scalactic_2.12-derived-platform:3.1.0:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component
          - Variant 'runtime' capability org.scalactic:scalactic_2.12:3.1.0:
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'incremental-analysis' of a component```
chali commented 3 years ago

hey @yairogen I'm looking at how we deal with on our side and our internal projects apply this plugin together with lint.

@CompileStatic
class ScalaPluginCheckPlugin implements Plugin<Project> {

    private final String SCALA_ANALYSIS_TASK_PREFIX = 'incrementalScalaAnalysis'

    @Override
    void apply(Project project) {
        project.plugins.withType(ScalaPlugin) {
            project.afterEvaluate {
                project.configurations.each {
                    if (it.name.startsWith(SCALA_ANALYSIS_TASK_PREFIX)) {
                        it.extendsFrom = [] as Iterable<Configuration>
                        assert !it.extendsFrom
                    }
                }
            }
        }
    }
}

I think the difference could be missing afterEvaluate in your case. Other differences seem to be related to the fact that it is a statically compiled plugin and that it can be applied before the scala plugin. This should not be a problem if you have the workaround directly in your build file.

Note this not necessarily a lint issue but anything which tries to resolve those configurations would end up with the problem.

yairogen commented 3 years ago

@chali Indeed this resolves the issue:

afterEvaluate {

    configurations.all {
        if (name.startsWith("incrementalScalaAnalysis")) {
            extendsFrom = []
        }
    }
}

However, I don't see any of my sub projects (gradle projects that are pointed by my top level gradle project) are scanned. Do I need to define the plugin in each one?

Also, why are these warnings? warning unused-dependency one or more classes in commons-io:commons-io:2.4 are required by your code directly (no auto-fix available)

If I use directly - then this is not "unused", no?

chali commented 3 years ago

I think the rule has a couple of modes that it reports and actually, in this case, it is saying that in your code you consume classes from commons-io but you don't have a direct dependency on it.

I should add a caveat that those rules are not in the best shape, there is a bunch of issue about false positive and missed dependencies. We, unfortunately, don't have currently bandwidth to focus on them and we are not even using them internally at this moment to avoid those issues.