Kotlin / kotlinx-atomicfu

The idiomatic way to use atomic operations in Kotlin
Other
925 stars 59 forks source link

Cannot find a version of 'org.jetbrains.kotlinx:atomicfu' that satisfies the version constraints #469

Open GuilhE opened 2 months ago

GuilhE commented 2 months ago

atomicfu was already on 0.25.0 and working, but suddenly when running for Android I'm getting:

Execution failed for task ':shared:compileDebugKotlinAndroid'.
> Error while evaluating property 'friendPathsSet$kotlin_gradle_plugin_common' of task ':shared:compileDebugKotlinAndroid'.
   > Could not resolve all files for configuration ':shared:debugCompileClasspath'.
      > Could not resolve org.jetbrains.kotlinx:atomicfu:0.25.0.
        Required by:
            project :shared
         > Cannot find a version of 'org.jetbrains.kotlinx:atomicfu' that satisfies the version constraints:
              Dependency path ':shared:unspecified' --> 'org.jetbrains.kotlinx:atomicfu:0.25.0'
              Constraint path ':shared:unspecified' --> 'org.jetbrains.kotlinx:atomicfu:{strictly 0.23.2}' because of the following reason: version resolved in configuration ':shared:debugRuntimeClasspath' by consistent resolution

project build.gradle:

plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.android.library) apply false
    alias(libs.plugins.kotlinx.compose) apply false
    alias(libs.plugins.kotlinx.compose.compiler) apply false
    alias(libs.plugins.kotlinx.atomicfu) apply false
}

shared build.gradle:

plugins {
    ...
    alias(libs.plugins.kotlinx.atomicfu)
    //id("org.jetbrains.kotlinx.atomicfu") version "0.25.0" // -> this fails too
}

Screenshot 2024-09-03 at 11 08 03

No problem running for iOS, Desktop and Wasm.

ps: I've checked if any of other dependencies uses atomicfu and they do, but none on 0.23.2 they are on 0.24.0. And as I said it was already working. The only change was bumping Kotlin version, but I've rolledback and the problem still remains. Cleaned all caches too. 🤷🏼

GuilhE commented 2 months ago

I've found this:

Screenshot 2024-09-03 at 11 48 36 Screenshot 2024-09-03 at 11 51 23

My project has 2 modules shared and shared-ui (depends on first). Atomicfu is used by the first:

.shared-appleMain.cinteropLibraries.json:

[
  {
    "moduleId": "org.jetbrains.kotlinx:atomicfu:0.25.0",
    "file": ".../.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/org.jetbrains.kotlinx-atomicfu-0.25.0-iosMain-cinterop/org.jetbrains.kotlinx_atomicfu-cinterop-interop-l0JTDg.klib",
    "sourceSetName": "iosMain"
  }, ...
]

.shared-ui-appleMain.cinteropLibraries.json:

[
  {
    "moduleId": "org.jetbrains.kotlinx:atomicfu:0.23.2",
    "file": ".../.kotlin/metadata/kotlinTransformedCInteropMetadataLibraries/org.jetbrains.kotlinx-atomicfu-0.23.2-iosMain-cinterop/org.jetbrains.kotlinx_atomicfu-cinterop-interop-l0JTDg.klib",
    "sourceSetName": "iosMain"
  }, ...
]

Questions:

  1. Where is 0.23.2 coming from?
  2. Why it works for all targets except Android?
fzhinkin commented 2 months ago

@GuilhE could you please share some project where the problem reproduces? It would help a lot with tracking the root cause down.

GuilhE commented 2 months ago

@GuilhE could you please share some project where the problem reproduces? It would help a lot with tracking the root cause down.

Yes, you can try this: https://github.com/GuilhE/WhosNext just bump:

Screenshot 2024-09-03 at 15 05 38

fzhinkin commented 2 months ago

Thanks!

Adding an explicit dependency on atomicfu:0.25.0 to shared's commonMain dependencies seems to solve the issue:

        commonMain.dependencies {
            implementation(libs.kotlinx.coroutines.core)
            implementation(libs.kotlinx.serialization)
            implementation(libs.kmp.settings)
            api(libs.kmp.viewmodel)
            api(libs.kmp.koin.core)
            api(libs.kmp.kermit)
            implementation("org.jetbrains.kotlinx:atomicfu:0.25.0")
        }

But it's unclear to me where the problematic dependency on 0.23.2 is coming from.

GuilhE commented 2 months ago

Adding an explicit dependency on atomicfu:0.25.0 to shared's commonMain dependencies seems to solve the issue:

If I remember correctly, recently, the dependency configuration was moved from "lib dependency" to "plugin dependency" correct? In other words, it should not be necessary to add it as a commonMain dependency. 🤔

fzhinkin commented 2 months ago

If I remember correctly, recently, the dependency configuration was moved from "lib dependency" to "plugin dependency" correct?

That's correct. And that's how the project got Dependency path ':shared:unspecified' --> 'org.jetbrains.kotlinx:atomicfu:0.25.0'. It's unclear, thought, where the constraint on 0.23.2 is coming from, but explicit dependency on 0.25.0 lifts it off.

GuilhE commented 2 months ago

@fzhinkin I've another project and I've noticed the same atomicfu reference of 0.23.2 version inside .kotlin folder. I've no atomicfu definition in my project. The depencies are:

 commonMain.dependencies {
    implementation(compose.runtime)
    implementation(compose.foundation)
    implementation(compose.material3)
    implementation(compose.ui)
}

So, is it compose-multiplatform introducing this problem?

fzhinkin commented 2 months ago

@GuilhE Yes, the dependency on 0.23.2 is indeed from the Compose libraries.

I guess, the problem has something to do with that fact that AtomicFU plugin works only with Kotlin JVM and Multiplatform plugins, but it does not support Android Gradle plugin.

So, I was wrong about

And that's how the project got Dependency path ':shared:unspecified' --> 'org.jetbrains.kotlinx:atomicfu:0.25.0'.

as it should not be configured by the plugin (or, to be more precise, that dependency should only be added to native targets).

I'm yet to figure out how releaseCompileClasspath and other relative configurations are set.

GuilhE commented 2 months ago

Should I submit a request for the compose-multiplatform team to update their version to match the latest atomicfu release while the atomicfu team addresses the dependency issue?

fzhinkin commented 2 months ago

Should I submit a request for the compose-multiplatform team to update their version to match the latest atomicfu release while the atomicfu team addresses the dependency issue?

Updating version in Compose won't solve the problem in general. So I don't think this issue should drive version updates in Compose.

fzhinkin commented 2 months ago

Related issue: https://github.com/Kotlin/kotlinx-atomicfu/issues/145

colinrtwhite commented 1 month ago

Related YouTrack issue: https://youtrack.jetbrains.com/issue/CMP-5831