我创建了一个空白项目:
mkdir gradleExp
cd gradleExp
gradle init
#1.basic 1.groovy随机名称
1.使用以下内容更新空的build.gradle
plugins {
id 'java'
}
repositories {
google()
mavenCentral()
}
dependencies {
implementation "androidx.browser:browser:1.4.0"
}
然后我就跑
dependencies --configuration compileClasspath
它返回了一个失败:
但是如果我用androidx.browser:browser:1.0.0
替换build.gradle
中的androidx.browser:browser:1.4.0
,那么它就可以完美地工作:
androidx.browser:browser:1.4.0
有什么问题?如何知道失败的确切原因?我的gradle版本是7.5.1,我从https://gradle.org/下载了它
注意:如果可以的话,用--debug
参数我可以看到:
[调试] [组织.gradle.内部.组件.模型.组件属性匹配器]从候选项中[]为{组织.gradle.类别=库,组织. gradle.依赖性.绑定=外部,组织. gradle.jvm.环境=标准jvm,组织. gradle. jvm.版本=8,组织. gradle.库元素=类,组织. gradle.用法=java-api}选择了匹配项[][androidx.浏览器:浏览器:1.4.0变体版本变体发布变体发布变体发布ApiPublication,androidx.浏览器:浏览器:1.4.0变体发布变体发布运行时发布,androidx.浏览器:浏览器:1.4.0变体源元素]
我不知道问题是否出在这里,但看起来Gradle无法选择变体(即:日志中的Selected matches []
)
这是gradle-module-metadata
的内容,如果它可以帮助:
{
"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"
}
]
}
]
}
1条答案
按热度按时间68bkxrlz1#
即使是
androidx.browser:browser:1.2.0
也会工作得很好,就像预期的那样。这里是问题,在
androidx.browser:browser:1.2.0
或1.0.0
中,正如你提到的,输出完全符合预期。为什么?对于版本1.2.0和1.0.0,只有两种类型的工件
pom
和arr
,它们不会导致解析问题。对于版本1.4.0,有4种类型,分别为
source
、aar
、gradle-module-metadata
和pom
在处理Gradle时,您只能假设最优先考虑的是
gradle-module-metadata
,根据这里的官方文档,这实际上是正确的。很明显,解析
gradle-module-metadata
时存在问题,因此让我尝试重新配置顺序根据Gradle文档,您可以通过以下方式轻松实现
所以repositories部分的代码应该如下所示
这将导致他们忽略
gradle-module-metadata
并优先考虑pom.xml
由于某些原因,这将不会按预期的方式运行,并且它不会工作,除非我添加了
configurations.implementation.canBeResolved = true
整个
build.gradle
看起来像结果将仅显示使用
gradle dependencies
命令或gradle dependencies --configuration implementation
的实现部分的依赖关系,以获得有限的输出。