Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Gradle Module Metadata for Kotlin Multiplatform dependencies #909

Open
artem-zinnatullin opened this issue May 31, 2023 · 7 comments

Comments

@artem-zinnatullin
Copy link
Contributor

Hi team, we've faced an issue with upgrade of androidx dependencies from 1.5.0-alpha04 to 1.5.0-beta01, looks like now instead of publishing Android .aar files directly, there is now additional -android artifact published which should be used to get .aar files.

The .pom files don't point to -android artifacts, however Gradle Module Metadata .module files do!

rules_jvm_external might need to add support for Gradle Module Metadata files to resolve such artifacts correctly or Google needs to fix .poms, but supporting Gradle Module Metadata files might be more sustainable for future Kotlin Multiplatform artifacts in general.


A bit more detailed debugging on an example artifact foundation-layout:1.5.0-beta01

.pom files of androidx dependencies that depend on foundation-layout:1.5.0-beta01 like androidx.compose.animation:animation:1.5.0-beta01 don't point to -android artifact correctly

<dependency>
    <groupId>androidx.compose.foundation</groupId>
    <artifactId>foundation-layout</artifactId>
    <version>1.5.0-beta01</version>
    <scope>runtime</scope>
    <type>aar</type>
</dependency>

So just relying on .pom files will get us nowhere...


However, there is additional Gradle Module Metadata file published for each artifact which correctly points to -android artifact.

  1. Download https://dl.google.com/android/maven2/androidx/compose/foundation/foundation-layout/1.5.0-beta01/foundation-layout-1.5.0-beta01.module

  2. Note that it has bunch of -published entries which point to foundation-layout-android (-android) .module file

{
      "name": "releaseApiElements-published",
      "attributes": {
        "org.gradle.category": "library",
        "org.gradle.usage": "java-api",
        "org.jetbrains.kotlin.platform.type": "androidJvm"
      },
      "available-at": {
        "url": "../../foundation-layout-android/1.5.0-beta01/foundation-layout-android-1.5.0-beta01.module",
        "group": "androidx.compose.foundation",
        "module": "foundation-layout-android",
        "version": "1.5.0-beta01"
      }
},
  1. Download https://dl.google.com/android/maven2/androidx/compose/foundation/foundation-layout-android/1.5.0-beta01/foundation-layout-android-1.5.0-beta01.module

  2. This file now points to correct -android.aar

"files": [
        {
          "name": "foundation-layout-release.aar",
          "url": "foundation-layout-android-1.5.0-beta01.aar",
          "size": 535787,
          "sha512": "06b2aaa6edd18647d6d0fae97ac6fa5e38f135a11183bcdabe4358f61f0de57472e8fff6c078cba5082da1b50f3447f36ce339dba8c054b2f89a7a25d5684921",
          "sha256": "4984eb1b708b9060fb6e70455cf245f7b9604909fca7895c15ebfd8bfd678309",
          "sha1": "e4176d6f734a92095e7f2d59a668af6571cbc6c3",
          "md5": "70bceeb3ccccd0d5557e369548f7d786"
        }
      ]

It seems like rules_jvm_external needs to add support for .module files to resolve Kotlin Multiplatform artifacts correctly :/

@artem-zinnatullin
Copy link
Contributor Author

@Bencodes pointed me to a draft PR #807 by @shs96c which uses Gradle dependency resolver, I wonder if as a side-effect of it rules_jvm_external will get support for Gradle Module Metadata and cover such cases as this issue?

@shs96c
Copy link
Collaborator

shs96c commented Jun 1, 2023 via email

@artem-zinnatullin
Copy link
Contributor Author

Totally agree, pom files should be fixed by Google.

But also going forward we might want compatibility with Gradle Module Metadata .module files in the future for better support of Kotlin Multiplatform artifacts, I think that module file better indicates different platform (JVM, Android, iOS, JS, Common) specific artifacts than the POM files can.

Filed an issue against Google to fix pom files https://issuetracker.google.com/issues/285353844

@AlexBurdu
Copy link

It looks like Google fixed the pom issue, but still rules_jvm_external is trying to fetch aar when no <package> is specified for androidx dependencies: https://issuetracker.google.com/issues/285353844#comment39

@geaden
Copy link

geaden commented Dec 16, 2023

@shs96c @Bencodes Is there a possible workaround on bazel side to fix the issue? It's not possible to upgrade to Jetpack Compose 1.5.x for now using normal dependencies.

@ahumesky
Copy link
Contributor

androidx.annotation:annotation:1.6.0 (2/22/2023) is published with gradle module metadata:
https://maven.google.com/web/index.html?q=annotation#androidx.annotation:annotation:1.6.0

and rules_jvm_external will download and use the "empty" jar there, making it look like you've depended on the right thing but javac not finding it. This is a very common dependency, and very common transitive dependency, so even if you try to use 1.5.0, something might easily upgrade you to 1.6.0 or later.

@arunkumar9t2
Copy link

w.r.t androidx.annotation issue, this can be temporarily worked around by adding a override_target that maps annotation to annotation-jvm

Like done here

override_targets = {
        "androidx.annotation:annotation": "@maven//:androidx_annotation_annotation_jvm",
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants