Kotlinx.coroutines: Gradle versions above 4.7 cannot resolve kotlinx-coroutines-core with GRADLE_METADATA feature enabled

Created on 15 Sep 2018  Â·  37Comments  Â·  Source: Kotlin/kotlinx.coroutines

When attempting to resolve kotlinx-coroutines-core, Gradle versions above 4.7 show the following message:

> Could not resolve all files for configuration ':source:compileClasspath'.
   > Could not resolve org.jetbrains.kotlinx:kotlinx-coroutines-core:0.26.0.
     Required by:
         project :source
      > Could not resolve org.jetbrains.kotlinx:kotlinx-coroutines-core:0.26.0.
         > Could not parse module metadata https://jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-coroutines-core/0.26.0/kotlinx-coroutines-core-0.26.0.module
            > Unsupported format version '0.3' specified in module metadata. This version of Gradle supports format version 0.4 only.
bug

Most helpful comment

Are there any updates on this now that Android Studio 3.3 is in it's release candidate stage, and is close to being released? Also, does Gradle 5.0 help this issue at all since GRADLE_METADATA is enabled by default?

All 37 comments

I don't have this problem with 4.10 or 4.10.1.

I don't have this problem with 4.10 or 4.10.1.

If the dependency is already cached in ~/.gradle, this doesn't happen. Delete the user gradle cache and see if it happens then.

I used either 4.9 or 4.10 to get it in the first place though. In any case, trying now!

No problems. I also banish jcenter to be very last in my repository list so i'm likely pulling from maven central. Perhaps try adding mavenCentral first?

Tried adding mavenCentral first, to no effect. Let me try something else... This persists across two PCs I have, so I know it isn't just the PC I'm using.

@JakeWharton Try cloning https://gitlab.com/serebit/diskord and attempt to gradlew assemble. If you don't see the error I posted above, there's something weird going on. (Make sure to clear the Gradle cache in your home dir first)

It fails, but you also are enabling the features in your settings.gradle.kts which likely causes it:

enableFeaturePreview("GRADLE_METADATA")

Yep, that was it. Bless.

Although I'd say it's still something to keep an eye on, for when that feature is fully implemented in Gradle.

Actually, I'll reopen this, seeing as it is still an issue with the published library files.

Let's keep this open. Gradle metadata is an experimental Gradle feature and its format changes between Gradle version. Since we publish our libraries with Gradle 4.7 and our builds have Gradle metadata feature enable, you cannot use it from any other version of Gradle if you also happen to have Gradle metadata enabled. We'll figure out how to publish our libraries _without_ Gradle metadata.

Sounds like a good course of action. But now I'm wondering why you don't just update Gradle to a newer version that supports metadata version 4 to tide us over while you figure out how to disable metadata.

The Android Gradle plugin 3.3 requires Gradle 4.10 or higher which makes this especially problematic.

The problem is worse than that. We'll have to pick a version and then we'll have to you this version everywhere, and then, when a new Gradle version, we'll have to rebuild everything. Long story short, we should not be using Gradle metadata until it is stable.

So, the best choice for now is stick to use the gradle 4.6 instead ?
p.s: I'm using android with gradle plugin 3.2.1 and coroutines version 0.30.2, the problem still exist

[Update] I'm using gradle 4.7 and no issue. also the GRADLE_METADATA are enabled

Update Gradle to any version after 4.7, clear your .gradle folders, and try again. It’ll fail.

On Mon, Oct 29, 2018 at 6:10 PM, Budi Oktaviyan notifications@github.com wrote:

[Update] I'm using gradle 4.7 and no issue. also the GRADLE_METADATA are enabled

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.

Before
screen shot 2018-10-30 at 05 30 48

After
screen shot 2018-10-30 at 05 31 43

It was no issue from my side

Not just clean build. You have to manually delete your gradle caches at $HOME/.gradle and .gradle in your project directory.

On Mon, Oct 29, 2018 at 6:33 PM, Budi Oktaviyan notifications@github.com wrote:

Before
screen shot 2018-10-30 at 05 30 48

After
screen shot 2018-10-30 at 05 31 43

It was no issue from my side

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.

Yeah, I also clear all my cache in $GRADLE_HOME before. There was no issue on my side

And what gradle version are you using?

On Mon, Oct 29, 2018 at 6:33 PM, Budi Oktaviyan notifications@github.com wrote:

Before
screen shot 2018-10-30 at 05 30 48

After
screen shot 2018-10-30 at 05 31 43

It was no issue from my side

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.

Previously I'm using 4.10.2 and have the same problem like you, but after downgrading wrapper to 4.7 the problem was gone. Here is my project, maybe you can check it later -> https://github.com/budioktaviyan/movies-multiplatform (sorry, it still not a complete project since I'm just started build a sample) :)

Yeah, I’m aware that the problem doesn’t exist with 4.7. Downgrading to 4.7 fixed my issue, but only while I still had the dependency in the cache. If I switched back to 4.10.2 and cleared cache, it would happen again. That’s why the issue title mentions that the version has to be newer than 4.7.

On Mon, Oct 29, 2018 at 6:40 PM, Budi Oktaviyan notifications@github.com wrote:

Previously I'm using 4.10.2 and have the same problem like you, but after downgrading wrapper to 4.7 the problem was gone. Here is my project, maybe you can check it later (sorry, it still not a complete project since I'm just started build a sample) :)

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.

Are there any updates on this now that Android Studio 3.3 is in it's release candidate stage, and is close to being released? Also, does Gradle 5.0 help this issue at all since GRADLE_METADATA is enabled by default?

Android 3.3 now released today and upgrading and following prompt recommendations will lead you down a rabbit hole.

I would also add that SqlDelight 1.0 requires Gradle Metadata :(

That's not quite true. You can specify the common and each platform dependency manually with it disabled.

So I've been tricked :D https://github.com/square/sqldelight/issues/1149 . I'll try to figure out a solution

@JakeWharton Wow, I never realized enabling Gradle metadata was actually optional if you manually specify the dependencies... This could have saved me so much fustration these past couple montha during this transitional period. Thanks for the tip

@luca992 @JakeWharton what dependencies are we talking about manually specifying? Other than the platform-specific ones (i.e. coroutines-ios) being where they belong, and the common ones being where they belong, what needs to change if I disable metadata?

@dennisdrew Basically for example take sqldelight runtime (which was published with the new mpp):

with metadata enabled: enableFeaturePreview('GRADLE_METADATA')

kotlin {
    sourceSets {
        commonMain {
            kotlin.srcDirs +="build/sqldelight"
            dependencies {
                implementation "com.squareup.sqldelight:runtime:$sqldelight_version"
                }
        }
        iosMain
    }

    targets {
        fromPreset(presets.iosX64, 'ios')
    }
}

without metadata enabled becomes:

kotlin {
    sourceSets {
        commonMain {
            kotlin.srcDirs +="build/sqldelight"
            dependencies {
                implementation "com.squareup.sqldelight:runtime-metadata:$sqldelight_version"
                }
        }
        iosMain {
            dependsOn commonMain
            dependencies {
                implementation "com.squareup.sqldelight:runtime-iosarm64:$sqldelight_version"
            }
        }
    }

    targets {
        fromPreset(presets.iosArm64, 'ios')
    }
}

thanks @luca992. that makes sense and is helpful! Do you know if something similar has to be done in order to get coroutines to compile? I disabled metadata and now coroutines doesn't compile when building for iOS

@dennisdrew coroutines doesn't use the new mpp yet as far as I know.

so for common dependencies you add:

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"

and to ios dependencies you add:

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$kotlin_coroutines_version"

edit:

kotlinx-coroutines-core-native requires metadata... So you would need

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native_debug_ios_arm64:$coroutines_version"
implementation "org.jetbrains.kotlinx:atomicfu-native_debug_ios_arm64:0.11.12"

but that's hardcoding in the build type to debug. This issue could help with picking the correct dependency for a build type

@luca992 Okay, thank you. I'm doing that but doesn't look like it's resolving. This is what I have (smaller project w/o sqldelight) :

        commonMain.dependencies {
            implementation "org.jetbrains.kotlin:kotlin-stdlib-common"
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
        }

        androidMain.dependencies {
            implementation "org.jetbrains.kotlin:kotlin-stdlib"
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
        }

        iosMain.dependencies {
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
        }

@dennisdrew remove kotlinx-coroutines-core from commonMain

@luca992 tried :( but still not working. But I don't want to flood this thread w/ my problems--if you're on kotlinlang.slack and still feel like helping let me know, or shoot me an e-mail

Since version 1.1.1 kotlinx.corouintes are published with Gradle 4.10 and new metadata (0.4)

Was this page helpful?
0 / 5 - 0 ratings