bazel-contrib / rules_jvm_external

Bazel rules to resolve, fetch and export Maven artifacts
Apache License 2.0
336 stars 256 forks source link

Support for Gradle Module Metadata for Kotlin Multiplatform dependencies #909

Open artem-zinnatullin opened 1 year ago

artem-zinnatullin commented 1 year ago

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"
      }
},

3) 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

4) 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 commented 1 year ago

@Bencodes pointed me to a draft PR https://github.com/bazelbuild/rules_jvm_external/pull/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 commented 1 year ago

It’s possible the new resolver will be able to use the gradle module files, but Google should also fix their pom files so that they’re correct for people who use something other than just gradle (such as maven or sbt)On 31 May 2023, at 21:51, Artem Zinnatullin @.***> wrote: @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?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

artem-zinnatullin commented 1 year ago

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 commented 1 year ago

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 commented 11 months ago

@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 commented 7 months ago

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 commented 7 months ago

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",
},