无法从私有存储库加载 Maven 元数据。收到 403:禁止访问

Unable to load Maven meta-data from private repo. Received 403: Forbidden

我正在尝试通过 Maven 将私有依赖项附加到我的项目 (react-native-android) 中。不幸的是,当我尝试构建 ./gradlew assembleDebug 我的项目时收到以下错误消息。


返回错误信息如下:

> FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve com.facebook.react:react-native:0.19.+.
     Required by:
         project :app > project :react-native-i18n
      > Failed to list versions for com.facebook.react:react-native.
         > Unable to load Maven meta-data from https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml.
            > Could not get resource 'https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml'.
               > Could not GET 'https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml'. Received status code 403 from server: Forbidden

代码示例

repositories {
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    maven { url "https://xxxPRIVATE_REPOxxx/android" }
}

dependencies {
    implementation project(':react-native-i18n')
    implementation 'com.android.support:support-v4:+'
    implementation 'xxxPRIVATE_DEPENDENCYxxx:1.0.+'
}

我阅读了大量 post 并研究了 maven 和 gradle 的主题。这是我对我的问题的发现:

  1. 意味着我的 sequence of declaring maven 将从第一个声明的 maven 而不是以下 (maven xxxPRIVATE_REPOxxx) 获得 "correct/suitable" 模块

    The order of declaration determines how Gradle will check for dependencies at runtime. If Gradle finds a module descriptor in a particular repository, it will attempt to download all of the artifacts for that module from the same repository. You can learn more about the inner workings of dependency downloads.

  2. 返回 403 Forbidden 并不一定意味着我无权访问我正在尝试访问的存储库,但也 missing of resource

因此我在这里做了一个假设...在下载项目依赖项期间,Maven 循环遍历两个 Maven 存储库 (maven google & xxxPRIVATE_REPOxxx) 以获得合适的库。然而,当它到达 xxxPRIVATE_REPOxxx 时,它无法找到 maven-metadata.xml 因此结果为 https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml 和 403 Forbidden.

我的问题:

是否应该有一种方法来指示从哪个 Maven 获取哪个依赖项?

我正在想象这样的事情 implementation 'xxxPRIVATE_DEPENDENCYxxx:1.0.+' : xxxPRIVATE_REPOxxx(你懂我的意思)

我试过了:

  1. 正在将我的 Android-插件升级到 3.5.0
  2. 正在将我的 Gradle 版本升级到 5.6.4
  3. ./gradlew 在步骤 1 和 2 之后清理并重新构建

原来这个问题是因为第 3 方库 (react-native-i18n) 使用的 react native 依赖项太低了。 你可以在 react-native-i18n 的 build.gradle.

找到它
dependencies {
    compile 'com.facebook.react:react-native:0.12.+'
}

因此我的解决方法是将代码更新为

compile 'com.facebook.react:react-native:+'