定义多个 Maven 存储库时的 Gradle 传递依赖项解析问题



在我的 gradle 文件中存在多个 maven 存储库的情况下,我遇到了有关解决传递依赖项的问题。这是我的根和模块 gradle 文件的快照 -

根渐变 -

allprojects {
repositories {
maven {
name 'A'
url 'someUrl1'
credentials {
//
}
}
maven {
name 'B'
url 'someUrl2'
credentials {
//
}
}
}

模块级分级 -

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-analytics:11.0.4'
compile 'com.google.android.gms:play-services-auth:11.0.4'
compile 'com.google.android.gms:play-services-gcm:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.google.android.gms:play-services-maps:11.0.4'

}

我遇到的问题是,每次我执行 gradle 同步/构建时,gradle 都会尝试从 Repo 'B' 获取上述依赖项的某些传递依赖项的 maven 元数据文件。所有依赖项都存在于存储库"A"中。我不确定为什么即使"A"列在"B"上方,也要搜索存储库"B"以查找 maven-metadata。

奇怪的是,它不会导致任何构建失败,因为它最终会从本地 gradle 缓存中获取依赖项,但它显着增加了我的构建时间,因为它在每次构建期间都会进行多次网络调用。

我注意到的一件事是 11.0.4 版本的 gms 库使用方括号,即 [11.0.4] 来提及它们在 POM 文件中的依赖项版本。

为了从根本上解决问题,我将依赖项更新为 11.8.0,其中 POM 文件不使用方括号来提及其依赖项版本,问题消失了。

我不确定为什么POM文件中存在特定版本依赖项会导致此问题。

下面是一段 gradle 调试日志 -

23:24:26.977 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.DependencyGraphBuilder] Visiting configuration com.google.android.gms:play-services-analytics:11.0.4(default).
23:24:26.978 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.DynamicVersionResolver] Attempting to resolve version for com.google.android.gms:play-services-analytics-impl:[11.0.4] using repositories [C:UsersabcAppDataLocalAndroidSdkextrasm2repository, C:UsersabcAppDataLocalAndroidSdkextrasgooglem2repository, C:UsersabcAppDataLocalAndroidSdkextrasandroidm2repository, maven, maven2]
23:24:26.978 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ResourceVersionLister] Listing all in file:/C:/Users/abc/AppData/Local/Android/sdk/extras/m2repository/com/google/android/gms/play-services-analytics-impl/[revision]/play-services-analytics-impl-[revision].pom
23:24:26.978 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ResourceVersionLister] using org.gradle.internal.resource.local.FileResourceConnector@24522fcd to list all in file:/C:/Users/abc/AppData/Local/Android/sdk/extras/m2repository/com/google/android/gms/play-services-analytics-impl/
23:24:26.978 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.MavenMetadataLoader] parsing maven-metadata: C:UsersabcAppDataLocalAndroidsdkextrasgooglem2repositorycomgoogleandroidgmsplay-services-analytics-implmaven-metadata.xml
23:24:26.980 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading file:/C:/Users/abc/AppData/Local/Android/sdk/extras/google/m2repository/com/google/android/gms/play-services-analytics-impl/11.0.4/play-services-analytics-impl-11.0.4.pom
23:24:26.983 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] Metadata file found for module 'com.google.android.gms:play-services-analytics-impl:11.0.4' in repository 'C:UsersabcAppDataLocalAndroidSdkextrasgooglem2repository'.
23:24:26.983 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ResourceVersionLister] Listing all in file:/C:/Users/abc/AppData/Local/Android/sdk/extras/android/m2repository/com/google/android/gms/play-services-analytics-impl/[revision]/play-services-analytics-impl-[revision].pom
23:24:26.983 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ResourceVersionLister] using org.gradle.internal.resource.local.FileResourceConnector@24522fcd to list all in file:/C:/Users/abc/AppData/Local/Android/sdk/extras/android/m2repository/com/google/android/gms/play-services-analytics-impl/
23:24:26.984 [INFO] [org.gradle.cache.internal.DefaultCacheAccess] Creating new cache for metadata-2.36/module-versions, path C:Usersabc.gradlecachesmodules-2metadata-2.36module-versions.bin, access org.gradle.cache.internal.DefaultCacheAccess@334c9d50
23:24:26.984 [DEBUG] [org.gradle.cache.internal.LockOnDemandCrossProcessCacheAccess] Acquiring file lock for artifact cache (C:Usersabc.gradlecachesmodules-2)
23:24:26.989 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on artifact cache (C:Usersprimanda.gradlecachesmodules-2).
23:24:26.990 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 14924, lockId: -9157439162897582946). Pinged owner at port 56301
23:24:26.990 [DEBUG] [org.gradle.cache.internal.locklistener.DefaultFileLockContentionHandler] Gradle process at port 56301 confirmed unlock request for lock with id -9157439162897582946.
23:24:26.990 [DEBUG] [org.gradle.cache.internal.locklistener.DefaultFileLockContentionHandler] Gradle process at port 56301 confirmed unlock request for lock with id -9157439162897582946.
23:24:27.001 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on artifact cache (C:Usersabc.gradlecachesmodules-2).
23:24:27.001 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Opening cache module-versions.bin (C:Usersabc.gradlecachesmodules-2metadata-2.36module-versions.bin)
23:24:27.002 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Opening cache module-metadata.bin (C:Usersabc.gradlecachesmodules-2metadata-2.36module-metadata.bin)
23:24:27.004 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Using cached module metadata for module 'com.google.android.gms:play-services-analytics-impl:11.0.4' in 'maven'
23:24:27.004 [DEBUG] [org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor] Constructing external resource: https://someurl2/com/google/android/gms/play-services-analytics-impl/maven-metadata.xml

该问题确实是由 Gradle 解释为范围并因此触发动态版本解析的符号[11.0.4]引起的。

在进行动态版本解析时,Gradle 将在构建脚本中定义的所有存储库中进行搜索,以确保拥有所有可用版本的完整视图。 然后,Gradle 将在本地缓存检索到的信息,以提高后续构建的性能。

相关内容

  • 没有找到相关文章

最新更新