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
761 stars 88 forks source link

Unable to consume Kotlin MultiPlatform project #389

Open renatoathaydes opened 1 year ago

renatoathaydes commented 1 year ago

Hi, I believe this may not be a bug in this plugin, but I am not entirely sure, so I hope you can have a look to help me at least find out what's wrong.

I've added a Kotlin Multiplatform dependency to my JVM project using Gradle composite builds.

It's fairly simple and dependency resolution works, except when I use the lintGradle task.

Summary of my setup

On my JVM project, I include a single project of a separate Kotlin Multiplatform build:

// See composite builds: https://docs.gradle.org/current/userguide/composite_builds.html
// Note: ssi-libs is a submodule.
includeBuild('ssi-libs') {
    dependencySubstitution {
        substitute module('org:base58-jvm:0') using project(':base58')
    }
}

Now, in one of my subProjects, I depend on the module declared above:

dependencies {
    implementation 'org:base58-jvm:0', {
        exclude module: 'kotlin-stdlib-common'
    }
}

Listing the dependencies of my project, I can see that Gradle finds it successfully:

compileClasspath - Compile classpath for compilation 'main' (target  (jvm)).
...
   org:base58-jvm:0 -> project :ssi-libs:base58

And I can build my application and run it without issues.

Problem running lintGradle

When I run the lintGradle task, however, I get the following error:

Execution failed for task ':lintGradle'.
> Could not resolve all dependencies for configuration ':org:implementationDependenciesMetadata'.
   > Could not resolve org:base58-jvm:0.
     Required by:
         project :identityserver:oauth
      > The consumer was configured to find a usage of 'kotlin-api' of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we cannot choose between the following variants of project :ssi-libs:base58:
          - jsApiElements
          - jvmApiElements
          - jvmRuntimeElements
          - nativeApiElements
        All of them match the consumer attributes:
          - Variant 'jsApiElements' capability org:base58:0.3.0 declares a usage of 'kotlin-api' of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js':
              - Unmatched attributes:
                  - Provides attribute 'org.gradle.jvm.environment' with value 'non-jvm' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but the consumer didn't ask for it
          - Variant 'jvmApiElements' capability org:base58:0.3.0 declares an API of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attributes:
                  - Provides attribute 'org.gradle.jvm.environment' with value 'standard-jvm' but the consumer didn't ask for it
                  - Provides its elements packaged as a jar but the consumer didn't ask for it
          - Variant 'jvmRuntimeElements' capability org:base58:0.3.0 declares a runtime of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attributes:
                  - Provides attribute 'org.gradle.jvm.environment' with value 'standard-jvm' but the consumer didn't ask for it
                  - Provides its elements packaged as a jar but the consumer didn't ask for it
          - Variant 'nativeApiElements' capability org:base58:0.3.0 declares a usage of 'kotlin-api' of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Unmatched attributes:
                  - Provides attribute 'artifactType' with value 'org.jetbrains.kotlin.klib' but the consumer didn't ask for it
                  - Provides attribute 'org.gradle.jvm.environment' with value 'non-jvm' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.native.target' with value 'macos_x64' but the consumer didn't ask for it
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'jsRuntimeElements' capability org:base58:0.3.0 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js':
              - Incompatible because this component declares a usage of 'kotlin-runtime' of a component and the consumer needed a usage of 'kotlin-api' of a component
          - Variant 'mainSourceElements' capability org:base58:0.3.0:
              - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its usage (required a usage of 'kotlin-api')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'common')
          - Variant 'metadataApiElements' capability org:base58:0.3.0 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common':
              - Incompatible because this component declares a usage of 'kotlin-metadata' of a component and the consumer needed a usage of 'kotlin-api' of a component
          - Variant 'nativeCInteropApiElements' capability org:base58:0.3.0 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a usage of 'kotlin-cinterop' of a component and the consumer needed a usage of 'kotlin-api' of a component
          - Variant 'nativeMetadataElements' capability org:base58:0.3.0 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a usage of 'kotlin-metadata' of a component and the consumer needed a usage of 'kotlin-api' of a component
          - Variant 'testResultsElementsForTest' capability org:base58:0.3.0:
              - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its usage (required a usage of 'kotlin-api')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'common')

I have no idea why this task is having issues deciding which "variant" it should use, given Gradle itself seems to know it's a JVM project (given my project wheere I import this lib is JVM-only).

Perhaps there's a way for me to explicitly declare that I only want the jvmRuntimeElements?

Or is it possible for this plugin to resolve the ambiguity automatically?

Any help would be appreciated, even if you can just show me how to ignore this dependency from the linter, for example!