JLLeitschuh / ktlint-gradle

A ktlint gradle plugin
MIT License
1.48k stars 164 forks source link

Could not resolve project java-platform #553

Open BraisGabin opened 2 years ago

BraisGabin commented 2 years ago

After I updated from 10.0.0 to 10.2.0 (same happens with 10.1.0) I'm getting this issue:

Could not determine the dependencies of task ':backend:test'.
> Could not resolve all task dependencies for configuration ':backend:testRuntimeClasspath'.
   > Could not resolve project :bom.
     Required by:
         project :backend
      > The consumer was configured to find a runtime of a platform compatible with Java 11, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'. However we cannot choose between the following variants of project :bom:
          - ktlint
          - runtimeElements
        All of them match the consumer attributes:
          - Variant 'ktlint' capability project:bom:unspecified declares a component, and its dependencies declared externally:
              - Unmatched attributes:
                  - Doesn't say anything about its component category (required a platform)
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about its usage (required a runtime)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
          - Variant 'runtimeElements' capability project:bom:unspecified declares a runtime of a platform:
              - Unmatched attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'apiElements' capability project:bom:unspecified declares a platform:
              - Incompatible because this component declares an API of a component and the consumer needed a runtime of a component
              - Other compatible attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
          - Variant 'enforcedApiElements' capability project:bom-derived-enforced-platform:unspecified:
              - Incompatible because this component declares an API of an enforced platform and the consumer needed a runtime of a platform
              - Other compatible attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
          - Variant 'enforcedRuntimeElements' capability project:bom-derived-enforced-platform:unspecified declares a runtime of a component:
              - Incompatible because this component declares an enforced platform and the consumer needed a platform
              - Other compatible attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')

The :bom project is a bill-of-materials project. Basically it applies this plugin:

plugins {
    `java-platform`
}

I know that with JVM8 and 10.1.0 it works but it doesn't with JVM11 and 10.1.0.

Fun fact, if I run ./gradlew ktlintFormat it works perfectly. The problem is running the task tests on JVM modules (the android ones work perfectly).

As a workaround I did this:

subprojects {
    if (this.name != "bom") {
        apply(plugin = "org.jlleitschuh.gradle.ktlint")

        configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
            version.set("0.43.2")
        }
    }
}

I tried to create a fast reproducible project but I couldn't reproduce it. Tell me if this error message gives you enough information.

gciatto commented 2 years ago

I'm getting the same issue on my Kotlin multi-platform project, using Kt v1.6.10, Gradle 7.3.3 and KtLint 10.2.1

JLLeitschuh commented 2 years ago

This may be resolved by this: https://github.com/JLLeitschuh/ktlint-gradle/pull/571