Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading from Gradle 5.1.1 to 6.0.1 breaks Kotlin multiplatform build

Tags:

I've upgraded my Kotlin multiplatform project to use Gradle 6.0.1:

gradle wrapper --gradle-version 6.0.1 --distribution-type all

and now my build is breaking. It doesn't recognize the common modules I add as a dependency to my project:

dependencies {
    commonMainApi("mygroup:mylib:$myversion")
}

I'm using the Kotlin DSL and this project is also a multiplatform project. What I get is a wall of text detailing all the imports which can't be resolved (all supposed to be imports from a common module in my dependency to a common module in my project).

The only thing I did was to upgrade to Gradle 6.0.1. If I restore the previous state my build is OK. What am I doing wrong?

like image 489
Adam Arold Avatar asked Dec 19 '19 16:12

Adam Arold


1 Answers

This is most likely connected with the fact that Gradle 6.0+ doesn't eagerly request the *.module metadata files from a repository unless the *.pom of the module contains a special marker, which was absent in *.poms published with older Gradle versions (pre-5.3, I believe)

Those *.module metadata files are needed to properly interpret a single dependency as both the common code metadata used to analyze the common sources of your project and the platform-specific artifacts that your targets are built against. Without that, the dependency is resolved to the library's root module which has no artifacts at all.

To fix this on the consumer side, you can make Gradle request those *.module metadata files by adding this statement to the repository declaration in your build scripts:

repositories {
    jcenter { 
        metadataSources { 
            gradleMetadata()
            mavenPom() 
        }
    }
    // or, if you are using a custom Maven repository:
    maven("https://my.repo.com") { 
        metadataSources { 
            gradleMetadata()
            mavenPom() 
        } 
    }
}

In the Gradle docs: Supported metadata sources


UPD: JitPack seems to remove the Gradle module metadata marker (<!-- do_not_remove: published-with-gradle-metadata -->) from the POMs, which results in Gradle not requesting *.module metadata files. A similar workaround as described above can also be used.

like image 131
hotkey Avatar answered Oct 02 '22 14:10

hotkey