kotlinx-atomicfu icon indicating copy to clipboard operation
kotlinx-atomicfu copied to clipboard

Required org.gradle.usage 'kotlin-api' and found incompatible value 'kotlin-metadata'

Open kar opened this issue 5 years ago • 8 comments

Something is wrong when adding atomicfu to a Kotlin Native MPP project:

> Task :common:compileKotlinIos FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':common:compileKotlinIos'.
> Could not resolve all files for configuration ':common:iosCompileKlibraries'.
   > Could not resolve org.jetbrains.kotlinx:atomicfu-common:0.14.3.
     Required by:
         project :common
      > Unable to find a matching variant of org.jetbrains.kotlinx:atomicfu-common:0.14.3:
          - Variant 'metadata-api' capability org.jetbrains.kotlinx:atomicfu-common:0.14.3:
              - Incompatible attributes:
                  - Required org.gradle.usage 'kotlin-api' and found incompatible value 'kotlin-metadata'.
                  - Required org.jetbrains.kotlin.platform.type 'native' and found incompatible value 'common'.
              - Other attributes:
                  - Found org.gradle.status 'release' but wasn't required.
                  - Required org.jetbrains.kotlin.native.target 'ios_x64' but no value provided.
          - Variant 'metadata-commonMainMetadataElements' capability org.jetbrains.kotlinx:atomicfu-common:0.14.3:
              - Incompatible attribute:
                  - Required org.jetbrains.kotlin.platform.type 'native' and found incompatible value 'common'.
              - Other attributes:
                  - Found org.gradle.status 'release' but wasn't required.
                  - Required org.gradle.usage 'kotlin-api' and found compatible value 'kotlin-api'.
                  - Required org.jetbrains.kotlin.native.target 'ios_x64' but no value provided.

kar avatar Mar 31 '20 10:03 kar

Can you share how atomicfu is configured in your Gradle build scripts and what version of Gradle are you using, please?

elizarov avatar Mar 31 '20 11:03 elizarov

I have a similar issue with latest release:

> Task :util:event:compileKotlinJvm FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':util:event:compileKotlinJvm'.
> Could not resolve all files for configuration ':util:event:jvmCompileClasspath'.
   > Could not resolve org.jetbrains.kotlinx:atomicfu-common:0.14.3.
     Required by:
         project :util:event
      > Unable to find a matching variant of org.jetbrains.kotlinx:atomicfu-common:0.14.3:
          - Variant 'metadata-api' capability org.jetbrains.kotlinx:atomicfu-common:0.14.3:
              - Incompatible attributes:
                  - Required org.gradle.usage 'java-api' and found incompatible value 'kotlin-metadata'.
                  - Required org.jetbrains.kotlin.platform.type 'jvm' and found incompatible value 'common'.
              - Other attribute:
                  - Found org.gradle.status 'release' but wasn't required.
          - Variant 'metadata-commonMainMetadataElements' capability org.jetbrains.kotlinx:atomicfu-common:0.14.3:
              - Incompatible attributes:
                  - Required org.gradle.usage 'java-api' and found incompatible value 'kotlin-api'.
                  - Required org.jetbrains.kotlin.platform.type 'jvm' and found incompatible value 'common'.
              - Other attribute:
                  - Found org.gradle.status 'release' but wasn't required.

Here's build.gradle.kts of this module:

plugins {
    kotlin("multiplatform")
    id("kotlinx-atomicfu")
}

kotlin {
    jvm()
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(kotlin("stdlib-common"))
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val jvmMain by getting {
            dependencies {
                implementation(kotlin("stdlib"))
            }
        }
        val jvmTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
            }
        }
    }
}

I'm using Gradle 6.2.1.

Reverting the version back to 0.14.2 allows the module to compile.

drymarau avatar Apr 04 '20 07:04 drymarau

@drymarev Could you please check whether you have a dependency on atomicfu-common anywhere in your project globally?

Please search for atomicfu-common in your Gradle build scripts and in the ./gradlew dependencies report.

If your project or the source of the transitive dependency is a publicly available library, it would help us a lot to learn which library it is and check how exactly it got a dependency on atomicfu-common, which should not normally happen.

Anyway, if you find where the direct or transitive dependency on atomicfu-common comes from, you can either remove the direct dependency or exclude the transitive dependency.

Please let us know.

h0tk3y avatar Apr 07 '20 16:04 h0tk3y

I have similar issue with 0.14.3. atomicfu-common is only used in the commonMain block (if I comment implementation (...) line out, build passes).

matejdro avatar Apr 09 '20 20:04 matejdro

Could you please check whether you have a dependency on atomicfu-common anywhere in your project globally?

Please search for atomicfu-common in your Gradle build scripts and in the ./gradlew dependencies report.

@h0tk3y There is no dependency on atomicfu-common anywhere in the project apart from the one provided by the plugin. Though I have to mention that ktor 1.3.2 (which is also in the project) depends on atomicfu (but only on JVM artifact). Removing this dependency via Gradle does not fix the issue for me.

I've created a small project to illustrate the issue (https://github.com/drymarev/atomicfu-131). It doesn't have any other dependencies apart from stdlib and atomicfu. Dependency report looks like so:

$ ./gradlew :event:dependencies | grep --context atomicfu-common

commonMainCompileOnly (n)
\--- org.jetbrains.kotlinx:atomicfu-common:0.14.3 (n)

commonMainCompileOnlyDependenciesMetadata
--
--

commonMainCompileOnlyDependenciesMetadata
\--- org.jetbrains.kotlinx:atomicfu-common:0.14.3

commonMainImplementation (n)
--
--
|    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.71
\--- org.jetbrains.kotlinx:atomicfu:0.14.3
     \--- org.jetbrains.kotlinx:atomicfu-common:0.14.3

commonTestRuntimeOnly (n)
--
--

jvmCompileClasspath - Compile classpath for compilation 'main' (target jvm (jvm)).
+--- org.jetbrains.kotlinx:atomicfu-common:0.14.3 FAILED
+--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.71
+--- org.jetbrains.kotlinx:atomicfu:0.14.3
--
--

jvmCompileOnly - Compile only dependencies for compilation 'main' (target jvm (jvm)).
+--- org.jetbrains.kotlinx:atomicfu-common:0.14.3 FAILED
\--- org.jetbrains.kotlinx:atomicfu:0.14.3
     +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.71
--
--
jvmMainCompileOnlyDependenciesMetadata
\--- org.jetbrains.kotlinx:atomicfu:0.14.3
     \--- org.jetbrains.kotlinx:atomicfu-common:0.14.3

jvmMainImplementation (n)
--
--
|    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.71
+--- org.jetbrains.kotlinx:atomicfu:0.14.3
|    \--- org.jetbrains.kotlinx:atomicfu-common:0.14.3
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.71
|    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.71
--
--

metadataCompileClasspath - Compile classpath for compilation 'main' (target metadata (common)).
+--- org.jetbrains.kotlinx:atomicfu-common:0.14.3
\--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.71

--
--

metadataCompileOnly - Compile only dependencies for compilation 'main' (target metadata (common)).
\--- org.jetbrains.kotlinx:atomicfu-common:0.14.3 FAILED

metadataDefault

drymarau avatar Apr 10 '20 17:04 drymarau

Thank you! Let me take a look at the sample project...

h0tk3y avatar Apr 10 '20 17:04 h0tk3y

@drymarev Sorry for late reply! This issue will be fixed by the commit cffe6eeef. Until then, you can fix it using the following workaround applied to the project where such a failure happens (or to allprojects { ... } if there are multiple):

configurations.all {
    withDependencies { 
        removeIf { it.name == "atomicfu-common" }
    }
}

h0tk3y avatar Apr 22 '20 18:04 h0tk3y

Thanks, @h0tk3y. Works like a charm.

drymarau avatar Apr 23 '20 07:04 drymarau