Home > Net >  gradle dependencies FAILED for an unknown reason (maybe variant selection in metadata?)
gradle dependencies FAILED for an unknown reason (maybe variant selection in metadata?)

Time:11-22

I create a blank project :

  1. mkdir gradleExp
  2. cd gradleExp
  3. gradle init # 1.basic 1.groovy random name
  4. update the empty build.gradle with the following
plugins {
    id 'java'
}
repositories {
    google()
    mavenCentral()
}

dependencies {
    implementation "androidx.browser:browser:1.4.0"
}

Then I run

dependencies --configuration compileClasspath

it's return me a failure:

enter image description here

But if i replace in build.gradle androidx.browser:browser:1.4.0 by androidx.browser:browser:1.0.0 then it's work perfectly :

enter image description here

What's wrong with androidx.browser:browser:1.4.0? how to know the exact reason of the failure ? My gradle version is 7.5.1 and I downloaded it from https://gradle.org/

Note: If it's can help, with the --debug parameter I can see :

[DEBUG] [org.gradle.internal.component.model.ComponentAttributeMatcher] Selected matches [] from candidates [androidx.browser:browser:1.4.0 variant releaseVariantReleaseApiPublication, androidx.browser:browser:1.4.0 variant releaseVariantReleaseRuntimePublication, androidx.browser:browser:1.4.0 variant sourcesElements] for {org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.environment=standard-jvm, org.gradle.jvm.version=8, org.gradle.libraryelements=classes, org.gradle.usage=java-api}

I don't know if the problem is here but look like gradle cannot select a variant (ie : Selected matches [] in the log)

this is the content of the gradle-module-metadata if it's can help:

{
  "formatVersion": "1.1",
  "component": {
    "group": "androidx.browser",
    "module": "browser",
    "version": "1.4.0",
    "attributes": {
      "org.gradle.status": "release"
    }
  },
  "createdBy": {
    "gradle": {
      "version": "7.2"
    }
  },
  "variants": [
    {
      "name": "releaseVariantReleaseApiPublication",
      "attributes": {
        "org.gradle.category": "library",
        "org.gradle.dependency.bundling": "external",
        "org.gradle.libraryelements": "aar",
        "org.gradle.usage": "java-api"
      },
      "dependencies": [
        {
          "group": "androidx.core",
          "module": "core",
          "version": {
            "requires": "1.1.0"
          }
        },
        {
          "group": "androidx.annotation",
          "module": "annotation",
          "version": {
            "requires": "1.1.0"
          }
        },
        {
          "group": "com.google.guava",
          "module": "listenablefuture",
          "version": {
            "requires": "1.0"
          }
        }
      ],
      "files": [
        {
          "name": "browser-1.4.0.aar",
          "url": "browser-1.4.0.aar",
          "size": 203214,
          "sha512": "5fabb554ca4dbea2c367df0decf175fee0a90bbdd7cc641c645b80a26e8bd13e85d5031c51bfbab25582a07f66e3eee829fadfe8b2e4e3383c4d877ce37935b2",
          "sha256": "e1906f84512f1ea5e4c926dbb915789ad8f7494fa4ee9ad245163f76185cecda",
          "sha1": "403c3cf31622ec0c70b3c0633be3e903c8062104",
          "md5": "8b6dfac591dd4b320351218bae97040e"
        }
      ]
    },
    {
      "name": "releaseVariantReleaseRuntimePublication",
      "attributes": {
        "org.gradle.category": "library",
        "org.gradle.dependency.bundling": "external",
        "org.gradle.libraryelements": "aar",
        "org.gradle.usage": "java-runtime"
      },
      "dependencies": [
        {
          "group": "androidx.collection",
          "module": "collection",
          "version": {
            "requires": "1.1.0"
          }
        },
        {
          "group": "androidx.concurrent",
          "module": "concurrent-futures",
          "version": {
            "requires": "1.0.0"
          }
        },
        {
          "group": "androidx.interpolator",
          "module": "interpolator",
          "version": {
            "requires": "1.0.0"
          }
        },
        {
          "group": "androidx.core",
          "module": "core",
          "version": {
            "requires": "1.1.0"
          }
        },
        {
          "group": "androidx.annotation",
          "module": "annotation",
          "version": {
            "requires": "1.1.0"
          }
        },
        {
          "group": "com.google.guava",
          "module": "listenablefuture",
          "version": {
            "requires": "1.0"
          }
        }
      ],
      "files": [
        {
          "name": "browser-1.4.0.aar",
          "url": "browser-1.4.0.aar",
          "size": 203214,
          "sha512": "5fabb554ca4dbea2c367df0decf175fee0a90bbdd7cc641c645b80a26e8bd13e85d5031c51bfbab25582a07f66e3eee829fadfe8b2e4e3383c4d877ce37935b2",
          "sha256": "e1906f84512f1ea5e4c926dbb915789ad8f7494fa4ee9ad245163f76185cecda",
          "sha1": "403c3cf31622ec0c70b3c0633be3e903c8062104",
          "md5": "8b6dfac591dd4b320351218bae97040e"
        }
      ]
    },
    {
      "name": "sourcesElements",
      "attributes": {
        "org.gradle.category": "documentation",
        "org.gradle.dependency.bundling": "external",
        "org.gradle.docstype": "sources",
        "org.gradle.usage": "java-runtime"
      },
      "files": [
        {
          "name": "browser-1.4.0-sources.jar",
          "url": "browser-1.4.0-sources.jar",
          "size": 96524,
          "sha512": "cd150044fd65d22c61f9d724a18b6a7386e4aed98644b146ffef0447b4f6f93044cb9fe58590f6111d33723733abc34039896a88a974ab0e465d05534294b101",
          "sha256": "3acbcce900ca5c2d03eb70d93136fc732d3b64dec185eaa86de3e64dff8ee792",
          "sha1": "2a2741f63427dcdb3b6821dd17703bc16ced13a1",
          "md5": "9eed77c8c21aeed4da0477c8bc6b72b9"
        }
      ]
    }
  ]
}

CodePudding user response:

Even androidx.browser:browser:1.2.0 will work fine and as expected.

Here is the issue, in androidx.browser:browser:1.2.0 or 1.0.0 as you mentioned, The output is exactly as expected. why?

For version 1.2.0 and 1.0.0, there are only two types of artifacts pom and arr which cause no issue in resolving.

for version 1.4.0, There are 4 types which are source, aar, gradle-module-metadata, pom

By looking to those 4 when dealing with gradle, You can only assume that the top priority would be for gradle-module-metadata which is actually right according to the official docs here.

There is clearly an issue with resolving gradle-module-metadata , so let me try to re-configure the order

According to gradle docs, You can easily do that with the following

repositories {
    maven {
        url "http://repo.mycompany.com/repo"
        metadataSources {
            mavenPom()
            artifact()
        }
    }
}

So the code of the repositories section should look like this

repositories {
    
    mavenCentral()
    { metadataSources {
        mavenPom()
        }
    }
    google()
    { metadataSources {
        mavenPom()
        }
    }
}

This will cause them to ignore the gradle-module-metadata and prioritize the pom.xml

For some reason, This will not behave as expected, And It did not work unless I have added configurations.implementation.canBeResolved = true

so, The entire build.gradle would look like

plugins {

    id 'java'
}

repositories {
    
    mavenCentral()
    { metadataSources {
        mavenPom()
        }
    }
    google()
    { metadataSources {
        mavenPom()
        }
    }
}

configurations.implementation.canBeResolved = true


dependencies {
    implementation 'androidx.browser:browser:1.4.0'
}

And will result with only showing the dependencies of the implementation section using either gradle dependencies command or gradle dependencies --configuration implementation for limited output.

  • Related