如何向 Android Studio 构建添加额外的 Maven 存储库

Dal*_*ale 5 dependencies build maven android-studio

我已将以下内容添加到dependencies我的应用程序的一部分build.gradle

implementation 'org.seleniumhq.selenium:selenium-htmlunit-driver:3.56.0'

但我收到错误:

Could not find org.seleniumhq.selenium:selenium-htmlunit-driver:3.56.0.
Searched in the following locations:
   - https://dl.google.com/dl/android/maven2/org/seleniumhq/selenium/selenium-htmlunit-driver/3.56.0/selenium-htmlunit-driver-3.56.0.pom

   - https://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-htmlunit-driver/3.56.0/selenium-htmlunit-driver-3.56.0.pom

   - https://jcenter.bintray.com/org/seleniumhq/selenium/selenium-htmlunit-driver/3.56.0/selenium-htmlunit-driver-3.56.0.pom
 Required by:
     project :app
Run Code Online (Sandbox Code Playgroud)

因此,在项目build.gradle文件中,我添加了以下repositories部分:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()

        // ADDED THIS 2021 12 17
        maven {
            url("https://mvnrepository.com")
        }

        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
    }
}
Run Code Online (Sandbox Code Playgroud)

我认为这会起作用,因为当我使用浏览器导航到该域时,有一个包含selenium-htmlunit_driver_3.56.0mvnrepository.com的页面。

我期望的是会找到指定的依赖项。或者,我会得到一份报告,其中包含“在以下位置搜索:”下的另一行,但将该 Maven 行添加到项目 build.grade 中没有效果。

我需要做什么才能搜索到额外的 Maven 存储库?从条目(repo.maven.apache.org/maven2...)拉入的maven存储库mavenCentral()不包含我想尝试的selenium-htmlunit-drive版本。

这是使用 Artic Fox 2020.3.1 补丁 3。

我究竟做错了什么?

Dal*_*ale 9

Artic Fox 开始使用另一种技术,depedencyResolutionManagment该技术引入了这种令人头疼的情况,即build.grade不搜索应用程序级文件中的条目。

在这种情况下对我有用的是进入settings.gradle(而不是build.gradle改变:

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

为了更好地衡量,我将额外的存储库放入其中,settings.gradle结果如下:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) // WAS: FAIL_ON_PROJECT_REPOS
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
        maven {url 'https://mvnrepository.com'} // ADDED THIS
    }
}
Run Code Online (Sandbox Code Playgroud)

进行这些更改后,Android Studio 标准构建过程会自动下载适当的工件。